I have 2 Main entry points in a single application.
The first main starts the server, maps the controllers and starts some worker threads. These workers receive messages from cloud queues.
In case of increased load, I want to be able to add additional workers to do my job. So I have a second Main entry point in my application which I want to be able to start without starting the default server in spring-boot (as a client application) so as to avoid port conflict (and obviously which will lead to failure).
How do I achieve this?
Launching from the command line with
server
andclient
profilesTo use the same jar and same entry point with 2 different profiles, you should simply provide the Spring profile at runtime, to have distinct application-${profile}.properties loaded (and potentially Conditional Java config triggered).
Define 2 spring profiles (
client
andserver
):application-${profile}.properties
Have a single SpringBootApp and entry point:
Make this class your main-class.
src/main/resources/application-server.properties:
src/main/resources/application-client.properties:
Launch both profiles from the command line:
You may have
@Configuration
classes triggered conditionally based on the active profile too:Launching from the IDE with
server
andclient
profilesLaunchers:
You may specify additional configuration classes (specific to client or server):
src/main/resources/application-server.properties:
src/main/resources/application-client.properties: