There is good question about ability to add multiple tomcat connectors and bind them to separate controllers each.
The essense of Andy Wilkinson's good answer is here:
public static void main(String[] args) {
SpringApplicationBuilder parentBuilder
= new SpringApplicationBuilder(ApplicationConfiguration.class);
parentBuilder.child(ServiceOneConfiguration.class)
.properties("server.port:8080").run(args);
parentBuilder.child(ServiceTwoConfiguration.class)
.properties("server.port:8081").run(args);
}
I want to go on this futher and ask another question:
Is there a way to make each child application context to read some child specific application properties with support of all standard spring-boot's features, like profile-suffix file names etc.
One hypothetical way to achieve it:
Have three separate property files:
application.properties
child1.properties
child2.properties
And have ability to set one file for each context.
But what is important to me, that they must support all spring-boot magic. For example, if I activate new profile like passing command line argument --spring.profiles.active=dev
, then automagically not only these three files should be loaded (one for each context), but another set of files (if they exist) also should be loaded automatically:
application-dev.properties
child1-dev.properties
child2-dev.properties
Of course, these files should be searched at standard spring-boot's supported paths in defined order etc.
Is it possible out if the box of maybe with some coding?
Another hypothetical way to achieve it
Have only one application.properties
file (with support for profiles etc), but somehow to map prefixed properties to unprefixed properties of child contexts.
Example:
child1.server.port=8081
child1.foo=bar
child2.server.port=8082
child2.foo=baz
First child context should see these properties like if they were just:
server.port=8081
foo=bar
Second child context should see these properties like if they were just:
server.port=8082
foo=baz
So, standard spring-boot's autoconfigurations will work and correctly set tomcat's port etc.
I am not looking for specific approach (but if you ask me, I'm leaning towards second approach), but any working out-of-the-box or achievable with minimum conding apporach will suffice me.