Running two spring boot instances

Viewed 7784

I am using Intellij Idea IDE version 2019.2.3 and I want to run two instances of my spring boot application in different ports, but I got just one running instance. I start the application in the port 8081 and after it runs, I change the port to 8083 and run it again in parallel with the previous one but i got this error :

`The Tomcat connector configured to listen on port 8083 failed to start. The port may already be in use or the connector may be misconfigured.

And when I come to the browser i found that the first port stopped working, when the application runs successfully in the last port`

I have tried to add a new "run configuration" but got the same problem.

enter image description here

3 Answers

Use the VM options field of the Sprint Boot run/debug configuration to define the port via the

-Dserver.port=9090

property. If the ports are different, you'll be able to start multiple instances:

Running 2 instances on different ports

The screenshot shows 2 run configurations started at the same time, one has -Dserver.port=9090 VM option, another has -Dserver.port=9091.

It's possible to use 'Allow parallel run' run/debug configuration option in combination with server.port: ${random.int(value,[max])} spring boot's property. For instance, server.port: ${random.int(8088,8099)} so that while running the config the idea will pick some random port from the provided range as result you don't need to spawn multiple run/debug configurations if it's not necessary. In order not to get in collision please use a wider range. enter image description here

you can create instance or copy of an application by clicking "Run Button -> Run Configuration".

Then right click on your "Application name" -> click on "Duplicate".

Then choose "Arguments" tab -> In "VM Arguments" type this.

-Dserver.port=8001

8001 is the port number you can mention your port over there. screenshot below:

enter image description here enter image description here enter image description here

Related