【问题标题】:Multiple Spring-boot applications running on one Tomcat在一个 Tomcat 上运行多个 Spring-boot 应用程序
【发布时间】:2015-12-30 08:31:21
【问题描述】:

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

我有两个应用程序打包为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 等)发生冲突。是否有一些解决方法或无法实现此设置?

感谢您的任何回复!

【问题讨论】:

    标签: tomcat deployment spring-boot


    【解决方案1】:

    正如Spring Boot Reference 所说:

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

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

    【讨论】:

    • 谢谢!我错过了这个。
    • 我在同一个 tomcat 上部署了两个 Spring Boot 应用程序,并且两个应用程序具有相同的数据源。我得到 InstanceAlreadyExistsException: org.apache.tomcat.jdbc.pool.jmx:name=dataSourceMBean,type=ConnectionPool 。我已经设置了endpoints.jmx.domain=myapp endpoints.jmx.uniqueNames=true。但我仍然得到错误。任何建议
    • @Mukun 你能解决这个问题吗?
    • 我在 tomcat 中运行多个 Spring Boot 应用程序。但都连接到不同的数据库/架构。
    【解决方案2】:

    类似于@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 Boot 上为我工作1.5.9.RELEASE

    【讨论】:

      【解决方案3】:
      spring.jmx.default-domain=app-name
      spring.jmx.unique-names=true
      

      【讨论】:

        猜你喜欢
        • 2015-07-26
        • 2018-05-13
        • 2015-12-04
        • 2014-11-10
        • 2018-09-04
        • 2019-03-08
        • 1970-01-01
        • 1970-01-01
        • 2017-02-23
        相关资源
        最近更新 更多