Spring Boot sperate @ Configurations for multiple application contexts

I want to run one spring boot application, but it will listen on multiple ports.

The goal is to allow Apache to redirect multiple (sub) domains to the spring (Tomcat) boot application on different ports. Example:

example.com/** -> PORT 8080 client.example.com/** -> PORT 8090 employee.example.com/** -> PORT 8100 

As far as I understand from multiple threads on SO, I'm best off running a few @SpringBootApplication annotated classes from the same main class, right? ( https://stackoverflow.com/questions/355295/... )

I still do not understand how to configure each of these applications separately.

Let's say I launched these three Applications, as shown in the related post above:

 MainExampleApplication ClientExampleApplication EmployeeExampleApplication 

Now, for example, I want to have separate spring Security @Configuration for each of these applications, as well as @RequestMappings , which can have the same value (for example, "/").

How do I tell the @Configuration or @Controller classes to which Application they are assigned?

Or are there properties that can be passed to applications at startup to indicate which resources are responsible for the context?

I hope I don’t go in the wrong direction. I have experience with spring MVC and have configured some fairly simplified spring applications, but not with multiple contexts. I would be very happy if someone could lead me in the right direction. Thank you in advance.

UPDATE

As mentioned in iamiddy's answer and xeon's comments, I used spring Profiles for this. I provided a SpringApplicationBuilder profile for each of the contexts of my application at startup and used @Profile("some_profile") in @Components , which should only be available for some contexts.

+8
java spring spring-boot spring-mvc tomcat
source share
1 answer

Use Profiles great spring function, loading only beans associated with the profile. After that, run the application N times with various arguments port and profile

Example: this is how you start the first, do it for the rest N

java -jar -Dspring.profiles.active=production1 -Dserver.port=9000 app.jar

+6
source share

All Articles