Spring-cloud-config: Exception on deploying the second spring-boot application

Created on 29 Mar 2015  路  5Comments  路  Source: spring-cloud/spring-cloud-config

I'm using spring-boot on glassfish 3.1.2.2. Eureka service was deployed successfully. An next deploy of an other spring-boot service fails with the exception:

Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException:
  org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.cloud.context.environment.EnvironmentManager@46d77a7] with key 'environmentManager'; 
  nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager.

What I'm doing wrong?

question

Most helpful comment

I have

spring:
  application:
    name: my-app-name

in src/main/resources/application.yml (Gradle war build; I verified the file is in the war at WEB-INF/classes/application.yml) but I still got this exception deploying into Tomcat with other web apps.

I was able to solve this by defining both:

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

(I'm noting this here in case others searching for the exception land here, like I did.)

All 5 comments

If you have 2 Spring Boot apps in the same JVM you need to segregate the MBean namespace, e.g. set spring.jmx.default-domain to something unique (for a Spring Cloud app ${spring.application.name} should be unique, for instance), or else set endpoints.jmx.domain (only affects the Actuator endpoints).

Does this need to be done in the application.yml or bootstrap.yml? Does it matter what string you use for default domain? Does it affect anything? I will need to have tons of spring boot apps in one tomcat instance

Hi Dave - Just wondering if it makes sense to have Spring Boot automatically set the default value of spring.jmx.default-domain = ${spring.application.name} as default behavior. This would mean multiple Boot apps can automatically run in the same JVM without a JMX namespace collision. Is there a downside?

The downside for Spring Boot is that ${spring.application.name} is not routinely set. It makes more sense in Spring Cloud, but even then there is no guarantee it is unique, nor tags it is appropriate for a JMX domain.

I have

spring:
  application:
    name: my-app-name

in src/main/resources/application.yml (Gradle war build; I verified the file is in the war at WEB-INF/classes/application.yml) but I still got this exception deploying into Tomcat with other web apps.

I was able to solve this by defining both:

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

(I'm noting this here in case others searching for the exception land here, like I did.)

Was this page helpful?
0 / 5 - 0 ratings