Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat: HikariCP issue when deploying two applications with DB connection

I am trying to deploye two WAR files (app1.war and app2.war) on the same tomcat7 instance. I am getting this error :

Unable to register MBean [HikariDataSource (HikariPool-0)] with key
  'dataSource'; nested exception is javax.management.InstanceAlreadyExistsException:
  com.zaxxer.hikari:name=dataSource,type=HikariDataSource

I don't have this error if I have only one application deployed on tomcat. Is there a way to solve this issue?

like image 554
user1260928 Avatar asked Dec 15 '15 09:12

user1260928


2 Answers

in spring boot, jmx bean is loaded at run time and it scans your application. If two data sources are found, its going to throw javax.management.InstanceAlreadyExistsException. This can be resolved by defining the default jmx default domain name in your application.properties file as follows

spring.jmx.default-domain=app_name

I hope this helps.

like image 138
John Adeshola Avatar answered Nov 16 '22 08:11

John Adeshola


In Spring Boot you can change the name of the Hikari data source pool via application.properties:

spring.datasource.hikari.poolName=MyDataPoolName

or application.yml respectivly:

spring:
  datasource:
    hikari:
      pool-name: MyDataPoolName

Then Tomcat can load both applications and the name conflict is gone.

like image 36
Tobias Avatar answered Nov 16 '22 07:11

Tobias