在两个端口中启动 Spring Boot REST 控制器 [英] Starting Spring boot REST controller in two ports
问题描述
有没有办法让两个 rest 控制器在一个 Spring Boot 应用程序的两个不同端口上运行?
Is there a way to have two rest controller running on two different ports from one spring boot application ?
例如 Controller_A 在 http://localhost:8080 中运行,Controller_B 在 http://localhost:9090 在一个 SpringBoot 主应用程序中?
Say for example Controller_A running in http://localhost:8080 and Controller_B running in http://localhost:9090 in one SpringBoot main Application ?
推荐答案
这样做的一种方法实际上是创建两个应用程序属性;
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
这篇关于在两个端口中启动 Spring Boot REST 控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!