30

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.

Any help on how to fix this is highly appreciated.

Using 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.access$200(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.access$200(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.access$200(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.access$200(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.access$200(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.access$200(DefaultLifecycleProcessor.java:51)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)
sat
  • 5,489
  • 10
  • 63
  • 81
  • By default all endpoints are registered under the domain `org.springboot` and with a default name. These can be overridden by setting `endpoints.jmx.*` properties. See [here](http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html) . You might want to change either the domain per application or set the `endpoints.jmx.unique-name` to `true`. – M. Deinum Nov 13 '14 at 08:01
  • @M.Deinum - Thank you very much. Setting unique-name to true did the trick. What would the endpoints be registered as now?. Also, if you could please add this as an answer, I will accept it so it helps others as well. Thanks again! – sat Nov 13 '14 at 15:38
  • I have no idea what the actual names will be, might depend on what underlying strategy is used. You might need to take a look at the endpoint registration part of Spring Boot. – M. Deinum Nov 13 '14 at 18:51

6 Answers6

41

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

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

Sabir Khan
  • 9,826
  • 7
  • 45
  • 98
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
32

Disable JMX in application.properties by adding following property

spring.jmx.enabled = false
Gondy
  • 4,925
  • 4
  • 40
  • 46
  • 1
    That will git the application running but will not solve the issue – Arar Apr 10 '18 at 17:14
  • 2
    See the answer from @bigbadmouse below for a more detailed explanation of why this works. It helped me. In my case, I was getting the `InstanceAlreadyExistsException` when attempting to run my unit tests, so I added the line `spring.jmx.enabled = false` to my `src/test/resources/application.properties` file. – Danny Bullis Apr 11 '18 at 22:25
4

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

Here's my yml code

spring:
  jmx:
    default-domain: agentservice

endpoints: 
  jmx:
    domain: agentservice
    unique-names: true
VladimirSD
  • 401
  • 3
  • 11
3
spring:
  jmx:
    default-domain: agentservice

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

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

nickb
  • 59,313
  • 13
  • 108
  • 143
Narendra
  • 31
  • 1
3

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

Options are:

Option-1) Set spring.jmx.enabled=false
Source: 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

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

Anurag
  • 876
  • 12
  • 16
2

To augment Gondy's answer, which I voted up, below is a link that says exactly why 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"

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


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

bigbadmouse
  • 216
  • 1
  • 11
  • Thanks for your explanation, @Gondy's answer also helped me but I was wishing he'd added more information. This is very helpful. – Danny Bullis Apr 11 '18 at 22:22