Tomcat: HikariCP issue when deploying two applications with DB connection

痞子三分冷 提交于 2019-12-01 04:23:39

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.

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.

Give your data sources unique names. For example, if you have separate schemas for storing user and product data, you could name your data sources userDS and productDS, respectively.

Programmatic configuration


HikariDataSource userDS = new HikariDataSource();
userDS.setPoolName("userDS");
// Set other data source properties.

HikariDataSource productDS = new HikariDataSource();
productDS.setPoolName("productDS");
// Set other data source properties.

Spring configuration


<bean id="userDS" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
  <property name="poolName" value="userDS"/>
  ...
</bean>

<bean id="productDS" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
  <property name="poolName" value="productDS"/>
  ...
</bean>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!