I have a parent-child architecture for my Spring Boot application in which there is a separate child for each config file found in a directory.
I am trying to accomplish this using the SpringApplicationBuilder
and failing.
At the moment, my main
logic looks something like:
SpringApplicationBuilder parentBuilder = new SpringApplicationBuilder(ParentConfiguration.class)
.properties(Collections.singletonMap("application.dataTypeCount", propertySourceList.size()))
.logStartupInfo(false);
// for each property source, add it to a child application and start that application
for (PropertySource<?> propertySource : propertySourceList) {
parentBuilder
.child(ChildConfiguration.class)
.initializers(context -> context.getEnvironment().getPropertySources().addLast(propertySource))
.run(args);
}
This works pretty well at the moment.
However, I don't have the shutdown behavior I'd like. If any of the children fail to start up, I want every application to stop. What's the best way to achieve this? Seems like there should be something higher level than twiddling around with ApplicationEventListener
.