我试图避免使用组件扫描来减少我们的模块测试以及我们的Web应用程序中的启动时间。如何在不使用ComponentScan的情况下启动Spring Boot Web应用程序
当我更换@SpringBootApplication
与@SpringBootConfiguration @EnableAutoConfiguration
,我得到以下错误:
Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean
我可以手动导入EmbeddedServletContainerFactory
不知何故?
是的,即使代码是第三方库,您也可以“复制”代码内的配置(注释配置)。实际上,当您因任何原因必须覆盖配置时,它非常有用。在我的测试中,使用组件扫描或不使用的差异很小。我会避免它。 – rdllopes
看看'org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration'。这就是spring-boot如何创建一个'EmbeddedServletContainerFactory'。如果没有更多的信息,我不能说你为什么在测试中没有一个(如果你想知道原因,请尝试调试条件),但是如果你想注册你自己的工厂,只需复制适当的'EmbeddedServletContainerFactory 'EmbeddedServletContainerAutoConfiguration'中的bean配置。 – Pieter