在 tomcat 容器中具有多个 Web 应用程序的 Spring Boot 执行器抛出 javax.management.InstanceAlreadyExistsException 异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26901991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:12:25  来源:igfitidea点击:

Spring Boot actuator with multiple web applications in a tomcat container throws javax.management.InstanceAlreadyExistsException exception

springtomcatspring-boot

提问by sat

I am running multiple spring boot applications inside a tomcat container (not embedded - just standalone tomcat container). However, it is giving me the following exceptions when launching the web applications. It is not affecting the functionality of any of the web applications, but is nevertheless something I'd like to resolve to have a clean startup.

我在 tomcat 容器(不是嵌入式 - 只是独立的 tomcat 容器)中运行多个 spring boot 应用程序。但是,它在启动 Web 应用程序时给了我以下异常。它不会影响任何 Web 应用程序的功能,但仍然是我想要解决的问题,以实现干净启动。

Any help on how to fix this is highly appreciated.

非常感谢有关如何解决此问题的任何帮助。

Using Spring Boot 1.1.7

使用 Spring Boot 1.1.7

org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean@14bee2f1] wit
h key 'metricsEndpoint'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=metricsEndpoint
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:609)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.registerEndpoint(EndpointMBeanExporter.java:162)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.locateAndRegisterEndpoints(EndpointMBeanExporter.java:142)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.doStart(EndpointMBeanExporter.java:134)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.start(EndpointMBeanExporter.java:257)
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
        at org.springframework.context.support.DefaultLifecycleProcessor.access0(DefaultLifecycleProcessor.java:51)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112)
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:775)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:131)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:485)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
        at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142)


org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean@1be9493f] with key 'traceEndpoint'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=traceEndpoint
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:609)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.registerEndpoint(EndpointMBeanExporter.java:162)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.locateAndRegisterEndpoints(EndpointMBeanExporter.java:142)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.doStart(EndpointMBeanExporter.java:134)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.start(EndpointMBeanExporter.java:257)
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
        at org.springframework.context.support.DefaultLifecycleProcessor.access0(DefaultLifecycleProcessor.java:51)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)


org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean@533a21cd] with key 'dumpEndpoint'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=dumpEndpoint
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:609)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.registerEndpoint(EndpointMBeanExporter.java:162)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.locateAndRegisterEndpoints(EndpointMBeanExporter.java:142)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.doStart(EndpointMBeanExporter.java:134)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.start(EndpointMBeanExporter.java:257)
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
        at org.springframework.context.support.DefaultLifecycleProcessor.access0(DefaultLifecycleProcessor.java:51)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)


org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean@695b578c] with key 'autoConfigurationAuditEndpoint'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=autoConfigurationAuditEndpoint
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:609)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.registerEndpoint(EndpointMBeanExporter.java:162)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.locateAndRegisterEndpoints(EndpointMBeanExporter.java:142)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.doStart(EndpointMBeanExporter.java:134)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.start(EndpointMBeanExporter.java:257)
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
        at org.springframework.context.support.DefaultLifecycleProcessor.access0(DefaultLifecycleProcessor.java:51)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)


org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.boot.actuate.endpoint.jmx.ShutdownEndpointMBean@7271ef13] with key 'shutdownEndpoint'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=shutdownEndpoint
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:609)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.registerEndpoint(EndpointMBeanExporter.java:162)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.locateAndRegisterEndpoints(EndpointMBeanExporter.java:142)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.doStart(EndpointMBeanExporter.java:134)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.start(EndpointMBeanExporter.java:257)
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
        at org.springframework.context.support.DefaultLifecycleProcessor.access0(DefaultLifecycleProcessor.java:51)


org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean@34ea9086] with key 'configurationPropertiesReportEndpoint'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=configurationPropertiesReportEndpoint
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:609)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.registerEndpoint(EndpointMBeanExporter.java:162)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.locateAndRegisterEndpoints(EndpointMBeanExporter.java:142)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.doStart(EndpointMBeanExporter.java:134)
        at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.start(EndpointMBeanExporter.java:257)
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
        at org.springframework.context.support.DefaultLifecycleProcessor.access0(DefaultLifecycleProcessor.java:51)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)

回答by M. Deinum

By default all endpoints are registered under the domain org.springbootand with a default name. These can be overridden by setting endpoints.jmx.*properties. See here.

默认情况下,所有端点都在域下注册org.springboot并使用默认名称。这些可以通过设置endpoints.jmx.*属性来覆盖。见这里

You might want to change either the domain per application or set the endpoints.jmx.unique-namesto true.

您可能希望更改每个应用程序的域或将 设置endpoints.jmx.unique-names为 true。

回答by Gondy

Disable JMX in application.properties by adding following property

通过添加以下属性在 application.properties 中禁用 JMX

spring.jmx.enabled = false

回答by VladimirSD

Unique names did not work for me. I had to also add a default domain.

唯一名称对我不起作用。我还必须添加一个默认域。

Here's my yml code

这是我的 yml 代码

spring:
  jmx:
    default-domain: agentservice

endpoints: 
  jmx:
    domain: agentservice
    unique-names: true

回答by Narendra

spring:
  jmx:
    default-domain: agentservice

endpoints: 
  jmx:
    domain: agentservice
    unique-names: true

Works above config with me while deploying multiple instances on same JVM

在同一个 JVM 上部署多个实例时,与我一起在配置之上工作

回答by bigbadmouse

To augment Gondy's answer, which I voted up, below is a link that says exactlywhy it works. PhilWebb says "It turns out registering the JMX information by default can cause some issues if you use Spring's Test Context Framework. .. By default, tests with @ContextConfiguration keep contexts open"and "I think we need to change spring.datasource.jmx-enabled to default to false and make this one opt-in"

为了增加我投票支持的 Gondy 的答案,下面是一个链接,说明它的工作原理。PhilWebb 说“事实证明,如果您使用 Spring 的测试上下文框架,默认情况下注册 JMX 信息会导致一些问题。.. 默认情况下,使用 @ContextConfiguration 的测试保持上下文打开”“我认为我们需要更改 spring.datasource.jmx - 启用默认为 false 并选择加入“

See GitHub(at "philwebb commented on 7 Nov 2014")

请参阅GitHub(在“philwebb 于 2014 年 11 月 7 日发表评论”)



I appreciate this isnt a unique answer. but this problem has been beating me for some time, Gondy's answer helped me and then I subsequently found out why and wanted to share that extra information in the only way available to me

我很欣赏这不是一个独特的答案。但是这个问题已经困扰我一段时间了,Gondy 的回答帮助了我,然后我找到了原因,并希望以我可用的唯一方式分享这些额外信息

回答by Anurag

I got this error org.springframework.jmx.export.UnableToRegisterMBeanException due to javax.management.InstanceAlreadyExistsException while deploying multiple webapps (Spring Boot in my case) on a single Tomcat server.
After some searching on the web I found this:
"With spring.jmx.enabled set to true (the default), any beans in the context that are MBeans will be automatically registered with the JMX server."
Source: https://github.com/spring-projects/spring-boot/issues/9179

在单个 Tomcat 服务器上部署多个 web 应用程序(在我的情况下为 Spring Boot)时,由于 javax.management.InstanceAlreadyExistsException,我收到了这个错误 org.springframework.jmx.export.UnableToRegisterMBeanException。
在网上搜索后,我发现了这一点:
将 spring.jmx.enabled 设置为 true(默认值),上下文中的 MBean 将自动注册到 JMX 服务器。
来源:https://github .com/spring-projects/spring-boot/issues/9179

Options are:

选项是:

Option-1)Set spring.jmx.enabled=false
Source: https://github.com/spring-projects/spring-boot/issues/9179

选项-1)设置 spring.jmx.enabled=false
来源:https: //github.com/spring-projects/spring-boot/issues/9179

Option-2)Provide unique names to JMX beans for each webapp deployed
spring.jmx.default-domain: app1
spring.jmx.default-domain: app2
Source: https://github.com/jhipster/generator-jhipster/issues/874

选项 2)为每个部署的
Web应用程序提供唯一的 JMX bean 名称spring.jmx.default-domain:app1
spring.jmx.default-domain:app2
来源:https: //github.com/jhipster/generator-jhipster/issues/ 874

Option-3)Change the names of the beans itself, in each webapp
@Bean
public DataSource app1DataSource() {...}
@Bean
public DataSource app2DataSource() {...}

选项 3)在每个 webapp 中更改 bean 本身的名称
@Bean
public DataSource app1DataSource() {...}
@Bean
public DataSource app2DataSource() {...}