Reputation: 16301
I have a batch application developed with Spring Boot. My batch application needs dependencies from spring-boot-starter-web
. Specifically I need a REST client with spring-hateoas
and jackson-databind
support. How can I disable the embedded Tomcat from starting? What excludes do I need to use?
@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);
}
}
At least, these were not enough, since it ends with an exception:
@EnableAutoConfiguration(exclude = {
EmbeddedServletContainerAutoConfiguration.class,
WebMvcAutoConfiguration.class,
EmbeddedTomcat.class,
DispatcherServletAutoConfiguration.class
})
The exception is:
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.
Upvotes: 2
Views: 1617
Reputation: 274
Late to the show but .web(boolean) is now deprecated in favour of:
new SpringApplicationBuilder(MyApplication.class).web(WebApplicationType.NONE).run(args);
See WebApplicationType for other enum values
https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/WebApplicationType.html
Upvotes: 0
Reputation: 116281
You can explicitly disable web support when you create your application. This means you don't need to exclude any auto-configuration:
@EnableAutoConfiguration
@EnableBatchProcessing
@EnableConfigurationProperties
@ComponentScan
public class MyBatchApplication {
public static void main(String... args) {
new SpringApplicationBuilder(MyBatchApplication.class).web(false).run(args);
}
}
Upvotes: 7