2014-10-30 31 views
2

我有一个使用Spring Boot开发的批处理应用程序。我的批处理应用程序需要依赖spring-boot-starter-web。具体而言,我需要支持spring-hateoasjackson-databind的REST客户端。如何禁用启动的嵌入式Tomcat?我需要使用什么排除?从加载禁用嵌入式servlet

​​

至少,这些还不够,因为它有一个例外结束:

@EnableAutoConfiguration(exclude = { 
    EmbeddedServletContainerAutoConfiguration.class, 
    WebMvcAutoConfiguration.class, 
    EmbeddedTomcat.class, 
    DispatcherServletAutoConfiguration.class 
}) 

唯一的例外是:

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean. 

回答

6

可以明确禁用网络支持,当你创建应用。这意味着你不需要排除任何自动配置:

@EnableAutoConfiguration 
@EnableBatchProcessing 
@EnableConfigurationProperties 
@ComponentScan 
public class MyBatchApplication { 
    public static void main(String... args) { 
     new SpringApplicationBuilder(MyBatchApplication.class).web(false).run(args); 
    } 
} 
+0

我已经得出了相同的结论,但有不正确的测试配置仍然启动tomcat的:) – RJo 2014-10-30 09:41:25

+0

哇凉的解决方案! – ACV 2015-09-04 21:21:53