javax.management.InstanceAlreadyExistsException:com.zaxxer.hikari:name = dataSource,type = HikariDataSource

时间:2018-08-11 08:42:21

标签: java spring-boot hikaricp

How can i solve this problem? 

哪个是最好的选择,以及如何做到

  1. 设置唯一的poolName
  2. 破坏先前的连接池

enter image description here

org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext
11-Aug-2018 16:05:53.863 SEVERE [Catalina-startStop-1] org.apache.catalina.core.ContainerBase.startInternal A child container failed during start
 java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[sss].StandardContext[]]
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        at ..........
...............
......
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[sss].StandardContext[]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
        ... 6 more
Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariDataSource (HikariPool-2)] with key 'dataSource'; nested exception is javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:name=dataSource,type=HikariDataSource
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:625)
        at 
..........................

org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 6 more
Caused by: javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:name=dataSource,type=HikariDataSource
        at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898)
        at .................
............
        at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)`

1 个答案:

答案 0 :(得分:5)

有两种方法可以解决此问题。

i。禁用jmx

ii。设置默认域和唯一名称(如果要启用jmx并具有同一应用程序的多个实例,则必须提供该名称)

要禁用jmx:

application.yml:

spring:
  jmx:
    enabled: false

或application.properties:

spring.jmx.enabled= false

如果需要启用jmx,请设置以下属性。

application.yml:

spring:
  jmx:
    default-domain: com.application.name
    unique-names: true