1

Is there a way to have two rest controller running on two different ports from one spring boot application ?

Say for example Controller_A running in http://localhost:8080 and Controller_B running in http://localhost:9090 in one SpringBoot main Application ?

shashantrika
  • 1,039
  • 1
  • 9
  • 29

1 Answers1

1

One way of doing this is actually creating two application properties;

app-A.properties

server.port=8080

app-B.properties

server.port=9090

And then in your controllers, put annotation like below;

@Profile("A")
public class ControllerA {
   ...
}

@Profile("B")
public class ControllerB {
   ...
}

Finally you need to launch your application twice with following settings;

java -jar -Dspring.profiles.active=A awesomeSpringApp.jar
java -jar -Dspring.profiles.active=B awesomeSpringApp.jar
Onur A.
  • 3,007
  • 3
  • 22
  • 37