一个 Tomcat 上的多个 Spring-引导应用程序 运行

Multiple Spring-boot applications running on one Tomcat

我可以在一个 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

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

感谢您的任何回复!

正如Spring Boot Reference所说:

If your application contains more than one Spring ApplicationContext you may find that names clash. To solve this problem you can set the endpoints.jmx.uniqueNames property to true so that MBean names are always unique.

endpoints.jmx.domain=myapp
endpoints.jmx.uniqueNames=true

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

spring.application.name=my-app-name
spring.jmx.default-domain=my-app-name

application.yaml:

spring:
  application:
    name: my-app-name
  jmx:
    default-domain: my-app-name

在 Spring 启动时为我工作 1.5.9.RELEASE

spring.jmx.default-domain=app-name
spring.jmx.unique-names=true