无法使用键“dataSource”注册 MBean [HikariDataSource(HikariPool-0)]

36

使用(Java8+Oauth2+MySql+Hazelcast+不带集群的http会话)组合时,我在生产模式下遇到以下错误。 Dev模式工作正常。

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

在日志中,数据源(hazelcast)创建的第一部分显示[dev]模式。不确定这是否是有意为之。

请帮助我解决此问题。

日志

Dec 12, 2014 2:44:11 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive D:\tools\apache-tomcat-7.0.55\webapps\re
tailenergy.war
[INFO] com.fg.re.ApplicationWebXml - Running with Spring profile(s) : prod
2014-12-12 14:44:19.125  WARN 1368 --- [ost-startStop-1] o.s.b.l.LoggingApplicat
ionListener       : Logging environment value '-Djava.util.logging.config.file="
D:\tools\apache-tomcat-7.0.55\conf\logging.properties"' cannot be opened and wil
l be ignored (using default location instead)
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more in
fo.
[DEBUG] com.fg.re.config.AsyncConfiguration - Creating Async Task Executor
[DEBUG] com.fg.re.config.MetricsConfiguration - Registering JVM gauges
[INFO] com.fg.re.config.MetricsConfiguration - Initializing Metrics JMX reportin
g
[INFO] com.hazelcast.instance.DefaultAddressPicker - null [dev] [3.2.5] Prefer I
Pv4 stack is true.
[INFO] com.hazelcast.instance.DefaultAddressPicker - null [dev] [3.2.5] Picked A
ddress[192.168.1.9]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localp
ort=5701], bind any local is true
[INFO] com.hazelcast.system - [192.168.1.9]:5701 [dev] [3.2.5] Hazelcast 3.2.5 (
20140814) starting at Address[192.168.1.9]:5701
[INFO] com.hazelcast.system - [192.168.1.9]:5701 [dev] [3.2.5] Copyright (C) 200
8-2014 Hazelcast.com
[INFO] com.hazelcast.instance.Node - [192.168.1.9]:5701 [dev] [3.2.5] Creating M
ulticastJoiner
[INFO] com.hazelcast.core.LifecycleService - [192.168.1.9]:5701 [dev] [3.2.5] Ad
dress[192.168.1.9]:5701 is STARTING
[INFO] com.hazelcast.cluster.MulticastJoiner - [192.168.1.9]:5701 [dev] [3.2.5]



Members [1] {
        Member [192.168.1.9]:5701 this
}

[INFO] com.hazelcast.core.LifecycleService - [192.168.1.9]:5701 [dev] [3.2.5] Ad
dress[192.168.1.9]:5701 is STARTED
[DEBUG] com.fg.re.config.CacheConfiguration - Starting HazelcastCacheManager
[INFO] com.hazelcast.util.HealthMonitor - [192.168.1.9]:5701 [dev] [3.2.5] memor
y.used=242.6M, memory.free=219.4M, memory.total=462.0M, memory.max=891.0M, memor
y.used/total=52.51%, memory.used/max=27.23%, load.process=-100.00%, load.system=
100.00%, load.systemAverage=-100.00%, thread.count=38, thread.peakCount=38, even
t.q.size=0, executor.q.async.size=0, executor.q.client.size=0, executor.q.operat
ion.size=0, executor.q.query.size=0, executor.q.scheduled.size=0, executor.q.io.
size=0, executor.q.system.size=0, executor.q.operation.size=0, executor.q.priori
tyOperation.size=0, executor.q.response.size=0, operations.remote.size=0, operat
ions.running.size=0, proxy.count=0, clientEndpoint.count=0, connection.active.co
unt=0, connection.count=0
[DEBUG] com.fg.re.config.DatabaseConfiguration - Configuring Datasource
[DEBUG] com.zaxxer.hikari.HikariConfig - HikariCP pool HikariPool-0 configuratio
n:
[DEBUG] com.zaxxer.hikari.HikariConfig - autoCommit......................true
[DEBUG] com.zaxxer.hikari.HikariConfig - catalog.........................
[DEBUG] com.zaxxer.hikari.HikariConfig - connectionCustomizer............com.zax
xer.hikari.HikariConfig$1@5a3cdbda
[DEBUG] com.zaxxer.hikari.HikariConfig - connectionCustomizerClassName...
[DEBUG] com.zaxxer.hikari.HikariConfig - connectionInitSql...............
[DEBUG] com.zaxxer.hikari.HikariConfig - connectionTestQuery.............
[DEBUG] com.zaxxer.hikari.HikariConfig - connectionTimeout...............30000
[DEBUG] com.zaxxer.hikari.HikariConfig - dataSource......................
[DEBUG] com.zaxxer.hikari.HikariConfig - dataSourceClassName.............com.mys
ql.jdbc.jdbc2.optional.MysqlDataSource
[DEBUG] com.zaxxer.hikari.HikariConfig - dataSourceJNDI..................
[DEBUG] com.zaxxer.hikari.HikariConfig - dataSourceProperties............{user=r
oot, url=jdbc:mysql://localhost:3306/retailenergy, password=<masked>, prepStmtCa
cheSqlLimit=2048, cachePrepStmts=true, useServerPrepStmts=true, prepStmtCacheSiz
e=250}
[DEBUG] com.zaxxer.hikari.HikariConfig - driverClassName.................
[DEBUG] com.zaxxer.hikari.HikariConfig - idleTimeout.....................600000
[DEBUG] com.zaxxer.hikari.HikariConfig - initializationFailFast..........true
[DEBUG] com.zaxxer.hikari.HikariConfig - isolateInternalQueries..........false
[DEBUG] com.zaxxer.hikari.HikariConfig - jdbc4ConnectionTest.............false
[DEBUG] com.zaxxer.hikari.HikariConfig - jdbcUrl.........................
[DEBUG] com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
[DEBUG] com.zaxxer.hikari.HikariConfig - maxLifetime.....................1800000

[DEBUG] com.zaxxer.hikari.HikariConfig - maximumPoolSize.................10
[DEBUG] com.zaxxer.hikari.HikariConfig - metricRegistry..................com.cod
ahale.metrics.MetricRegistry@4152b59f
[DEBUG] com.zaxxer.hikari.HikariConfig - minimumIdle.....................10
[DEBUG] com.zaxxer.hikari.HikariConfig - password........................<masked
>
[DEBUG] com.zaxxer.hikari.HikariConfig - poolName........................HikariP
ool-0
[DEBUG] com.zaxxer.hikari.HikariConfig - readOnly........................false
[DEBUG] com.zaxxer.hikari.HikariConfig - registerMbeans..................false
[DEBUG] com.zaxxer.hikari.HikariConfig - threadFactory...................
[DEBUG] com.zaxxer.hikari.HikariConfig - transactionIsolation............
[DEBUG] com.zaxxer.hikari.HikariConfig - username........................
[INFO] com.zaxxer.hikari.HikariDataSource - HikariCP pool HikariPool-0 is starti
ng.
[DEBUG] com.fg.re.config.DatabaseConfiguration - Configuring Liquibase
[INFO] com.fg.re.config.hazelcast.HazelcastCacheRegionFactory - Starting up Haze
lcastCacheRegionFactory
[DEBUG] com.fg.re.config.MailConfiguration - Configuring mail server
[INFO] com.fg.re.config.WebConfigurer - Web application configuration, using pro
files: [prod]
[DEBUG] com.fg.re.config.WebConfigurer - Initializing Metrics registries
[DEBUG] com.fg.re.config.WebConfigurer - Registering Metrics Filter
[DEBUG] com.fg.re.config.WebConfigurer - Registering Metrics Servlet
[DEBUG] com.fg.re.config.WebConfigurer - Registering Caching HTTP Headers Filter

[DEBUG] com.fg.re.config.WebConfigurer - Registering static resources production
 Filter
[DEBUG] com.fg.re.config.WebConfigurer - Registering GZip Filter
[INFO] com.fg.re.config.WebConfigurer - Web application fully configured
[INFO] com.fg.re.Application - Running with Spring profile(s) : [prod]
[INFO] com.fg.re.config.ThymeleafConfiguration - loading non-reloadable mail mes
sages resources
[WARN] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebAppl
icationContext - Exception encountered during context initialization - cancellin
g refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'mbeanExporter' defined in class path resource [org/springframework/conte
xt/annotation/MBeanExportConfiguration.class]: Invocation of init method failed;
 nested exception is org.springframework.jmx.export.UnableToRegisterMBeanExcepti
on: Unable to register MBean [HikariDataSource (HikariPool-0)] with key 'dataSou
rce'; nested exception is javax.management.InstanceAlreadyExistsException: com.z
axxer.hikari:name=dataSource,type=HikariDataSource
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1554) ~[spring-be
ans-4.0.8.RELEASE.jar:4.0.8.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans
-4.0.8.RELEASE.jar:4.0.8.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4
.0.8.RELEASE.jar:4.0.8.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:302) ~[spring-beans-4.0.8.RELEASE.jar:4.0.8.RELEAS
E]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.8.RELEA
SE.jar:4.0.8.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe
an(AbstractBeanFactory.java:298) ~[spring-beans-4.0.8.RELEASE.jar:4.0.8.RELEASE]

        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:193) ~[spring-beans-4.0.8.RELEASE.jar:4.0.8.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.
preInstantiateSingletons(DefaultListableBeanFactory.java:706) ~[spring-beans-4.0
.8.RELEASE.jar:4.0.8.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finish
BeanFactoryInitialization(AbstractApplicationContext.java:762) ~[spring-context-
4.0.8.RELEASE.jar:4.0.8.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:482) ~[spring-context-4.0.8.RELEASE.jar:4.0.8.
RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationConte
xt.refresh(EmbeddedWebApplicationContext.java:109) [spring-boot-1.1.9.RELEASE.ja
r:1.1.9.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.
java:691) [spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java
:320) [spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
        at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringA
pplicationBuilder.java:142) [spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
        at org.springframework.boot.context.web.SpringBootServletInitializer.cre
ateRootApplicationContext(SpringBootServletInitializer.java:89) [spring-boot-1.1
.9.RELEASE.jar:1.1.9.RELEASE]
        at org.springframework.boot.context.web.SpringBootServletInitializer.onS
tartup(SpringBootServletInitializer.java:51) [spring-boot-1.1.9.RELEASE.jar:1.1.
9.RELEASE]
        at org.springframework.web.SpringServletContainerInitializer.onStartup(S
pringServletContainerInitializer.java:175) [spring-web-4.0.8.RELEASE.jar:4.0.8.R
ELEASE]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContex
t.java:5479) [catalina.jar:7.0.55]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
[catalina.jar:7.0.55]
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:901) [catalina.jar:7.0.55]
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:87
7) [catalina.jar:7.0.55]
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
 [catalina.jar:7.0.55]
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083
) [catalina.jar:7.0.55]
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:
1880) [catalina.jar:7.0.55]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:51
1) [na:1.8.0_25]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_25
]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1142) [na:1.8.0_25]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:617) [na:1.8.0_25]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25]
Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable
 to register MBean [HikariDataSource (HikariPool-0)] with key 'dataSource'; nest
ed exception is javax.management.InstanceAlreadyExistsException: com.zaxxer.hika
ri:name=dataSource,type=HikariDataSource
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstan
ce(MBeanExporter.java:608) ~[spring-context-4.0.8.RELEASE.jar:4.0.8.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExpor
ter.java:533) ~[spring-context-4.0.8.RELEASE.jar:4.0.8.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.afterPropertiesSet(MBean
Exporter.java:415) ~[spring-context-4.0.8.RELEASE.jar:4.0.8.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1613) ~[spring
-beans-4.0.8.RELEASE.jar:4.0.8.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1550) ~[spring-be
ans-4.0.8.RELEASE.jar:4.0.8.RELEASE]
        ... 28 common frames omitted
Caused by: javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:na
me=dataSource,type=HikariDataSource
        at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437) ~[na
:1.8.0_25]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRep
ository(DefaultMBeanServerInterceptor.java:1898) ~[na:1.8.0_25]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamic
MBean(DefaultMBeanServerInterceptor.java:966) ~[na:1.8.0_25]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(
DefaultMBeanServerInterceptor.java:900) ~[na:1.8.0_25]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(D
efaultMBeanServerInterceptor.java:324) ~[na:1.8.0_25]
        at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.j
ava:522) ~[na:1.8.0_25]
        at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(M
BeanRegistrationSupport.java:195) ~[spring-context-4.0.8.RELEASE.jar:4.0.8.RELEA
SE]
        at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBe
anExporter.java:653) ~[spring-context-4.0.8.RELEASE.jar:4.0.8.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstan
ce(MBeanExporter.java:598) ~[spring-context-4.0.8.RELEASE.jar:4.0.8.RELEASE]
        ... 32 common frames omitted
[INFO] com.fg.re.config.hazelcast.HazelcastCacheRegionFactory - Shutting down Ha
zelcastCacheRegionFactory
[INFO] com.zaxxer.hikari.pool.HikariPool - HikariCP pool HikariPool-0 is shuttin
g down.
[DEBUG] com.zaxxer.hikari.pool.HikariPool - Before shutdown pool stats HikariPoo
l-0 (total=10, inUse=3, avail=7, waiting=0)
[DEBUG] com.zaxxer.hikari.pool.HikariPool - After shutdown pool stats HikariPool
-0 (total=0, inUse=0, avail=0, waiting=0)
[INFO] com.fg.re.config.CacheConfiguration - Remove Cache Manager metrics
[INFO] com.fg.re.config.CacheConfiguration - Closing Cache Manager
[INFO] com.hazelcast.core.LifecycleService - [192.168.1.9]:5701 [dev] [3.2.5] Ad
dress[192.168.1.9]:5701 is SHUTTING_DOWN
[INFO] com.hazelcast.initializer - [192.168.1.9]:5701 [dev] [3.2.5] Destroying n
ode initializer.
[INFO] com.hazelcast.instance.Node - [192.168.1.9]:5701 [dev] [3.2.5] Hazelcast
Shutdown is completed in 31 ms.
[INFO] com.hazelcast.core.LifecycleService - [192.168.1.9]:5701 [dev] [3.2.5] Ad
dress[192.168.1.9]:5701 is SHUTDOWN
[ERROR] org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'mbeanExporter' defined in class path resource [org/springframework/conte
xt/annotation/MBeanExportConfiguration.class]: Invocation of init method failed;
 nested exception is org.springframework.jmx.export.UnableToRegisterMBeanExcepti
on: Unable to register MBean [HikariDataSource (HikariPool-0)] with key 'dataSou
rce'; nested exception is javax.management.InstanceAlreadyExistsException: com.z
axxer.hikari:name=dataSource,type=HikariDataSource
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1554) ~[spring-be
ans-4.0.8.RELEASE.jar:4.0.8.RELEASE]

最新观察。之前我在同一个Tomcat上运行了两个JHipster Web应用程序。移除另一个应用程序后,错误消失了。我能知道原因吗?在生产环境中,有可能会在同一个Tomcat上运行两个JHipster Web应用程序。


请参见 https://dev59.com/Fa3la4cB1Zd3GeqPO5KK。 - Alex R
7个回答

41

我遇到了类似的问题,有两个jhipster应用程序实例在单个tomcat服务器上同时运行。

我也在https://github.com/jhipster/generator-jhipster/issues/874#issuecomment-113023849中发布了这个问题。

https://docs.oracle.com/javase/tutorial/jmx/mbeans/standard.html来看:

每个JMX MBean必须有一个对象名称。对象名称是JMX类ObjectName的一个实例,并且必须符合JMX规范定义的语法。即,对象名称必须包含域和一系列键属性。

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-jmx来看:

  1. JMX监控和管理 Java管理扩展(JMX)提供了一种标准机制以监控和管理应用程序。默认情况下,Spring Boot会创建一个带有bean id“mbeanServer”的MBeanServer,并公开任何使用Spring JMX注释(@ManagedResource、@ManagedAttribute、@ManagedOperation)注释的bean。

有关详细信息,请参见JmxAutoConfiguration类。

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java中检查JmxAutoConfiguration的代码,我看到其中有一个spring.jmx.default-domain属性,用于命名策略。

将该属性设置为某个值即可解决此问题。

spring.jmx.default-domain: test

域名可以是任意的,这似乎是避免两个应用程序名称冲突的合理方式。

由于我之前没有使用过JMX,因此我希望听取有关此解决方案的反馈意见。


15
或者您可以在application.properties文件中设置 spring.jmx.enabled=false 直接禁用JMX。 - Rolch2015
5
相反地,你可以忽略注册失败而不是禁用注册。我在@Configuration类中添加了@EnableMBeanExport(registration=RegistrationPolicy.IGNORE_EXISTING)注解。这样它只会忽略冲突而不是完全禁用。 - Ryan D
1
在application.properties中,spring.jmx.default-domain = some-name。 - basil

30

我通过为我的Tomcat上的每个Spring应用程序设置不同的spring.jmx.default-domain属性值来解决了这种问题,例如:

spring.jmx.default-domain=somevalue
在application.properties文件中。

2
这个答案是有效的,原因是多个WAR具有相同的JMX域会导致JMX bean名称冲突。 - Timmy Chiu
如何在单个Tomcat服务中托管多个应用程序的使用情况下将属性设置为随机值? - Kok How Teh
@KokHowTeh 或许你可以使用这个解决方案来生成随机值: https://www.logicbig.com/tutorials/spring-framework/spring-boot/random-properties.html - PowR
这应该是被接受的答案。清晰、简洁、直截了当,完美地解决了问题。 - Kshitij Bajracharya
这个属性解决了我的问题。 - Ashish Sharma

13

我尝试过的两种方法成功地在同一Tomcat中部署两个Hikari应用程序的方式是:不仅要更改poolName(1),还要更改DataSource(2)配置的bean名称。

@Bean(destroyMethod = "shutdown")
public DataSource dataSource2() {

    HikariConfig config = new HikariConfig();
    config.setPoolName("AARSHikaripool-1");

注意bean的名称为datasource2,而其他应用程序使用的是datasource!!

JHipster更新:

由于不再有datasource bean,因此在application.yml中添加以下内容:

spring:
    jmx:
        default-domain: [application_name]

1
你的解决方案有效,谢谢。 更加程序化的方法是使用Bean注释的“name”属性为每个应用程序提供单独的名称: @Bean(name = Application.APPLICATION_NAME + "DataSource") public DataSource dataSource() { } - minni
我删除了重复的Spring Boot应用程序,然后它就可以工作了!这就是我所需要的。 - Philip Rego
1
以上解决方案适用于在Weblogic 12.1.3上单个EAR中有多个Spring Boot WAR的情况。 - Tushar
如何在application.yml文件中设置动态随机值,以便在单个Tomcat服务中托管多个Web应用程序的使用情况下使用? - Kok How Teh
你需要修改生成这个yml文件的代码,更多细节请参考https://github.com/jhipster/generator-jhipster/blob/master/CONTRIBUTING.md。 - pv1

10

只需在您的配置文件中添加以下注释

@EnableMBeanExport(registration=RegistrationPolicy.IGNORE_EXISTING)

它会适合你的使用。


太棒了!谢谢!如果你有很多Spring单元测试,这将是最好的选择。 - tm1701

3

我在Tomcat 9中有多个应用程序和映射到域名,但以上方法都没有奏效,只能靠自己的改进来解决问题。

spring.jmx.default-domain=somevalue${random.uuid}

application.properties 文件中。

2
这似乎是您的应用程序正在重新部署,但是在取消部署时,容器没有调用HikariDataSourceclose()shutdown()方法。Spring应该有一个“destroy”属性(或类似的东西),可以设置为取消部署。
此外,请确保尽可能使用最新版本的HikariCP(2.2.5),我相信旧版本无法正确注销MBeans。
编辑:如果您在同一VM中有两个需要HikariCP的WAR,并且您想要注册MBeans,则需要将每个WAR设置为使用不同的poolName。我看到它正在使用默认池名称HikariPool-0

我除了按照Jhipster的默认步骤之外没有做任何明确的事情。我不确定两个wars。需要检查一下。感谢您的回复。 - Sudheer
如果你无法缩小问题的范围,你可以向Jhipster提出一个问题。如果这是一个问题,我们会提供帮助,我们和那些家伙相当友好。 - brettw
我也在使用HikariCP 2.2.5时遇到了同样的异常。我将向Jhipster记录此问题。另外,我不确定是否需要重新部署。我没有对上述组合中的Jhiipster进行任何修改。 - Sudheer

1
以下方法对我有效,随机化池名称jmx域名(spring.jmx.default-domain)(请参见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;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接