问题
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 ?
回答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
来源:https://stackoverflow.com/questions/54753599/starting-spring-boot-rest-controller-in-two-ports