Starting Spring boot REST controller in two ports

若如初见. 提交于 2021-02-11 15:35:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!