I have a spring boot app with a parent application context and a child application context with some legacy code. I would like to have a webapp in the parent application context, and have the child context be a non webapp.
I have my config and properties in application.yml, that gets loaded in the main class
@ComponentScan(...)
@PropertySource(value = "classpath:application.yml", factory = YamlPropertySourceFactory.class)
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class MyApplication(
public static void main(String[] args) {
new SpringApplicationBuilder(MyApplication.class)
.profiles("Prod")
.web(WebApplicationType.SERVLET)
.listeners(new MainAppListener()) // logging for some of the events
.child(LegacyServiceConfig.class)
.web(WebApplicationType.NONE)
.listeners(new LegacyAppListener()) // logging for some of the events
.run(args);
}
}
What I've tried so far:
- I don't have any web application type config in my application.yml (
spring.main.web-application-type). I hoped that the configuration I've specified thru code, in the above snippet would have worked, but it doesn't. Neither of the application contexts start as a webapp, effectively ignoring the configweb(WebApplicationType.SERVLET)in the above snippet. - I tried putting
spring.main.web-application-type=servletin my application.yaml. But that seems to apply this config to both parent and child application context. And both of them try to start as webapps, which is not what I want.
How do I get this to work? Any pointers?