【发布时间】:2016-09-08 07:45:55
【问题描述】:
Spring boot 非 web 应用,启动时出现以下错误
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185) ~[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
然后我尝试了以下方式
new SpringApplication().setWebEnvironment(false);
然后启动它仍然有上述错误。
然后尝试
@SpringBootApplication(exclude={SpringDataWebAutoConfiguration.class})
但仍然有同样的错误。
最后我尝试在application.properties中添加以下配置
spring.main.web-environment=false
这次成功了。
为什么前两种方式行不通?
【问题讨论】:
-
发布实际代码而不是 sn-p... 您的
main方法中有更多行。所以贴出应用类。 -
试试这个
@SpringBootApplication(exclude = {EmbeddedServletContainerAutoConfiguration.class, WebMvcAutoConfiguration.class})作为Suggested here -
@SanjayRawat 还是不行,请看github.com/zhugw/spring-boot-disable-web-environment
-
@M.Deinum 请参阅github.com/zhugw/spring-boot-disable-web-environment
标签: spring-boot