Search code examples
javaspringspring-bootwarcomponent-scan

How do I start a Spring Boot Web Application without using ComponentScan


I am trying to avoid component scanning to reduce start up time in our module tests, and in our web app in general.

When I replace @SpringBootApplication with @SpringBootConfiguration @EnableAutoConfiguration, I get the following error:

Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

Can I manually import the EmbeddedServletContainerFactory somehow?


Solution

  • Miloš and Pieter provided the means to find the answer. A minimal Spring Boot Web Application can be started with the following:

    @SpringBootConfiguration
    @Import({EmbeddedServletContainerAutoConfiguration.class})
    public class Application extends SpringBootServletInitializer {
       ...
    }
    

    ServerPropertiesAutoConfiguration.class might also be handy to pick up things like port number for the application.