ratkov_a
ratkov_a

Reputation: 53

Start two springboot apps in eclipse

Is it possible to start two spring boot applications in eclipse, in the same workspace in the same time? How can i set two different ports for that two spring boot applications?

Upvotes: 5

Views: 14022

Answers (4)

Eduardo Jaunez
Eduardo Jaunez

Reputation: 1

Yes, you can change the port using argument -Dserver.port=XXXX to override the properties value in Run Configuration windows, each time you launch the app. Keep in mind you must change on each launch to avoid a port collision.

Upvotes: 0

abhay singh
abhay singh

Reputation: 1

Follow these steps:

  1. Go to /src/main/resources/application.properties
  2. Add server.port= PortNo(for example server.port=8081 in first app's application.properties and server.port=8082 in second app's application.properties)
  3. Right-click on each application one by one and Run As Spring Boot App
  4. Go the browser and hit localhost:8081 for the first app and localhost:8082 for the second app, it should work.

Upvotes: 0

Omkar Puttagunta
Omkar Puttagunta

Reputation: 4156

Yes. It is possible to run two spring boot apps same time in the same workspace in eclipse. This is possible because each spring boot app comes with an embedded tomcat server and we have to make sure that each of them uses a different port number respectively.

In each spring boot application, add application.properties file in src/main/resources folder. To override the default 8080 port, you have to use server.port property in the application.properties file. Make sure you set different port in each of the application. For example, set server.port=8888 in one application and server.port=9999 in another application, so that app1 will run on 8888 port and app2 will run on 9999 port.

To scan for a free port (using OS natives to prevent clashes) use server.port=0.

Upvotes: 6

james_s_tayler
james_s_tayler

Reputation: 1933

You can specify the port that the embedded instance of tomcat runs on by putting server.port=[port number here] in your application.properties. If you want tomcat to run on a random port put server.port=0 in application.properties.

I'm not sure about running two instances in the same workspace, I've never tried. But if you try to deploy and both tomcat instances are trying to run on the same port you will get 'tomcat connector in a failed state'.

Upvotes: 1

Related Questions