简体   繁体   中英

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?

My suggestion is to first run your application with the debug flag on and write down all the activated auto-configurations. Then, disable auto-configuration and import those configurations by using @Import on your application class.

Alternatively, you can look at each of those configuration classes and see what Spring Boot configures for you and decide if you want to provide your own configurations instead - you can just mimic the auto-configuration classes and everything should work the same way.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM