I am getting below error in prod mode for (Java8+Oauth2+MySql+Hazelcast+no clustered http sessions) combination. Dev mode has worked fine.
Unable to register MBe
Two things I tried and they worked for deploying two Hikari apps in the same tomcat are: Not only change poolName(1) but also change bean name for DataSource(2) Configuration.
@Bean(destroyMethod = "shutdown")
public DataSource dataSource2() {
HikariConfig config = new HikariConfig();
config.setPoolName("AARSHikaripool-1");
Notice bean name is datasource2 while other app has datasource!!
Update for JHipster:
Since there is no datasource bean anymore, in application.yml add the following:
spring:
jmx:
default-domain: [application_name]
I solved this kind of problem by setting different value of spring.jmx.default-domain
property for each Spring applications on my Tomcat like:
spring.jmx.default-domain=somevalue
in application.properties file.
I was having a similar issue, with 2 jhipster application instances running alongside on a single tomcat server. I posted this also in https://github.com/jhipster/generator-jhipster/issues/874#issuecomment-113023849
From https://docs.oracle.com/javase/tutorial/jmx/mbeans/standard.html
Every JMX MBean must have an object name. The object name is an instance of the JMX class ?ObjectName and must conform to the syntax defined by the JMX specification. Namely, the object name must contain a domain and a list of key-properties.
From http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-jmx
- Monitoring and management over JMX Java Management Extensions (JMX) provide a standard mechanism to monitor and manage applications. By default Spring Boot will create an MBeanServer with bean id ‘mbeanServer’ and expose any of your beans that are annotated with Spring JMX annotations (@ManagedResource, @ManagedAttribute, @ManagedOperation).
See the JmxAutoConfiguration class for more details.
Checking the code of JmxAutoConfiguration in https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java I saw that there is a spring.jmx.default-domain property that is used in the naming strategy.
Setting that property to some value in one of my apps' application.properties solved this issue
spring.jmx.default-domain: test
As the domain name is arbitrary, it seems to me like a reasonable way to avoid name clashings between two apps.
Since I had no previous experience with JMX I would appreciate feedback on this solution.
This seems like your application is re-deploying, but when it un-deployed the container did not call the close()
or shutdown()
method on the HikariDataSource
. Spring should have a "destroy" property (or something akin) that can be set for un-deployment.
Also, make sure that you are using the latest version of HikariCP (2.2.5) if possible, I believe an old version did not unregister MBeans properly.
EDIT: if you have two WARs in the same VM that need HikariCP, and you want to register MBeans, you need to set each one to use a different poolName
. I see it is using the default pool name of HikariPool-0
.
The following approach worked for me, randomize the pool name jmx domain (spring.jmx.default-domain)(please see JmxAutoConfiguration) :
@Bean
public DataSource dataSource() throws SQLException {
HikariDataSource dataSource = new HikariDataSource(this);
dataSource.setPoolName("dataSource_" + UUID.randomUUID().toString());
return dataSource;
}
@Bean
@ConditionalOnMissingBean(value = ObjectNamingStrategy.class, search = SearchStrategy.CURRENT)
public ParentAwareNamingStrategy objectNamingStrategy() {
ParentAwareNamingStrategy namingStrategy = new ParentAwareNamingStrategy(new AnnotationJmxAttributeSource());
namingStrategy.setDefaultDomain("domain_" + UUID.randomUUID().toString());
return namingStrategy;
}
for me in tomcat 9 having multiple application and domain mapped. None of the above worked and had to improvise with
spring.jmx.default-domain=somevalue${random.uuid}
in application.properties