在一个Tomcat上运行多个Spring-boot应用程序

Sma*_*ajl 7 deployment tomcat spring-boot

我可以在一个Tomcat上运行两个(或更多)Spring启动应用程序吗?

我有两个应用程序打包为war文件,我想在一个Tomcat服务器上运行它们.但是,当我部署它们时,我得到以下异常:

org.springframework.jmx.export.UnableToRegisterMBeanException: 
    Unable to register MBean [org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean@2361d8ee] with key 'dumpEndpoint'; 
    nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=dumpEndpoint
Run Code Online (Sandbox Code Playgroud)

每个Spring-boot应用程序注册的默认端点(如/ health等)都会发生冲突.是否有一些解决方法或不可能实现此设置?

谢谢你的回复!

Mac*_*iak 10

正如Spring Boot Reference所说:

如果您的应用程序包含多个Spring ApplicationContext,您可能会发现名称发生冲突.要解决此问题,可以将endpoints.jmx.uniqueNames属性设置为true,以便MBean名称始终是唯一的.

endpoints.jmx.domain=myapp
endpoints.jmx.uniqueNames=true
Run Code Online (Sandbox Code Playgroud)


Dad*_*Moe 5

类似于@Maciej的答案。另一种方法是设置以下内容

spring.application.name=my-app-name
spring.jmx.default-domain=my-app-name
Run Code Online (Sandbox Code Playgroud)

application.yaml

spring:
  application:
    name: my-app-name
  jmx:
    default-domain: my-app-name
Run Code Online (Sandbox Code Playgroud)

在Spring Boot上为我工作 1.5.9.RELEASE