我有一个使用 Spring Boot 开发的批处理应用程序。我的批处理应用程序需要来自 spring-boot-starter-web
的依赖项。具体来说,我需要一个支持 spring-hateoas
和 jackson-databind
的 REST 客户端。如何禁用嵌入式 Tomcat 启动?我需要使用哪些排除项目?
@EnableAutoConfiguration(excludes = {
/** What do I need to put here? */
})
@EnableBatchProcessing
@EnableConfigurationProperties
@ComponentScan
public class MyBatchApplication {
public static void main(String... args) {
SpringApplication.run(MyBatchApplication.class, args);
}
}
至少,这些还不够,因为它以异常结束:
@EnableAutoConfiguration(exclude = {
EmbeddedServletContainerAutoConfiguration.class,
WebMvcAutoConfiguration.class,
EmbeddedTomcat.class,
DispatcherServletAutoConfiguration.class
})
异常(exception)情况是:
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.
最佳答案
您可以在创建应用程序时明确禁用网络支持。这意味着您不需要排除任何自动配置:
@EnableAutoConfiguration
@EnableBatchProcessing
@EnableConfigurationProperties
@ComponentScan
public class MyBatchApplication {
public static void main(String... args) {
new SpringApplicationBuilder(MyBatchApplication.class).web(false).run(args);
}
}
关于rest - 禁止加载嵌入式 servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26647888/