在两个端口启动Spring启动REST控制器

问题描述 投票:0回答:1

有没有办法在一个弹簧启动应用程序的两个不同端口上运行两个休息控制器?

比如在一个SpringBoot主应用程序中运行http://localhost:8080中运行的Controller_A和运行在http://localhost:9090中的Controller_B?

spring spring-boot spring-mvc spring-restcontroller
1个回答
0
投票

一种方法是实际创建两个应用程序属性;

app-A.properties

server.port=8080

app-B.properties

server.port=9090

然后在你的控制器中,添加如下的注释;

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

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

最后,您需要使用以下设置启动应用程序两次;

java -jar -Dspring.profiles.active=A awesomeSpringApp.jar
java -jar -Dspring.profiles.active=B awesomeSpringApp.jar
© www.soinside.com 2019 - 2024. All rights reserved.