如何启动两个春季启动应用程序

Ale*_*Tbk 0 spring tomcat spring-boot

我正在玩春季靴子.所以我想创建两个互相交互的微服务.我的问题是我无法启动它们,因为当第一个应用程序已经使用自己的tomcat运行时,第二个应用程序无法启动:

Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

谢谢!

geo*_*and 6

您需要更改第二个应用程序使用的端口(以避免相同TCP端口的冲突).一种方法是添加一个属性,如

server.port = 8090
Run Code Online (Sandbox Code Playgroud)

application.properties第二个申请


Jim*_*imB 5

另一种方法是将端口指定为命令行开关.这样可以更轻松地在运行时操作,而无需还原到属性设置,这些设置最终可能对您部署到的环境有效,也可能无效.

java -Dserver.port=8081 -jar target/springboot-0.0.1-SNAPSHOT.jar
Run Code Online (Sandbox Code Playgroud)