在使用druid数据源的时候遇到的问题
在tomcat 7.0下面部署两个项目,两个项目都是使用了druid数据连接池,单独启动一个项目的时候没有问题,把另外一个项目换为别的数据库连接池两个同时启动也没有问题,但是当两个项目放到这同一个tomcat下启动时就会出现下面的错误,求大神解答:@温少
环境:jdk1.8 + tomcat 7.0
架构:maven+spring boot+spring mvc+mybatis
Error starting ApplicationContext. To display the auto-configuration report enabled debug logging (start with --debug) 2015-05-17 18:09:42,[localhost-startStop-1] ERROR org.springframework.boot.SpringApplication - Application startup failed org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [{ CreateTime:"2015-05-17 18:09:38", ActiveCount:0, PoolingCount:0, CreateCount:0, DestroyCount:0, CloseCount:0, ConnectCount:0, Connections:[ ] } [ ]] with key 'dataSource'; nested exception is javax.management.InstanceAlreadyExistsException: com.alibaba.druid.pool:name=dataSource,type=DruidDataSource at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:625) at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:550) at org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:432) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:117) at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:108) at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:68) at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5456) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1229) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: javax.management.InstanceAlreadyExistsException: com.alibaba.druid.pool:name=dataSource,type=DruidDataSource at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324) at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522) at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:195) at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:670) at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:615) ... 24 more 2015-05-17 18:09:42,[localhost-startStop-1] INFO org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@37b73e96: startup date [Sun May 17 18:09:35 CST 2015]; root of context hierarchy 2015-05-17 18:09:42,[localhost-startStop-1] WARN org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception thrown from LifecycleProcessor on context close java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@37b73e96: startup date [Sun May 17 18:09:35 CST 2015]; root of context hierarchy at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:357) at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:877) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.java:150) at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:836) at org.springframework.boot.SpringApplication.run(SpringApplication.java:342) at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:117) at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:108) at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:68) at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5456) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1229) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(20)
今天也碰到了这个问题,看了一下,主要原因如@wenshao所言。注册到默认的jmx domain上了,导致已经存在的异常被抛出。
解决方案是,配置一下不同的jmx default-domain,区分开就行了。
回复
不同的项目设置不同的MBean范围
请问应该怎么处理这个问题? Springboot
回复
springboot可以这样设置 spring.jmx.default-domain: admin
这个更应该说是spring的bug,spring将实现了符合MBean规范的beans注册到mbeanserver中,但没处理好异常,所以悲剧了。
回复
同样问题,之前我用的durid的版本为1.0.20,tomcat下部署两个项目,运行正常,后发现7月份发布了23版本,于是我就更新为最新的1.0.23版本,同时配置参数增加了<property name="filters" value="stat,log4j" />;报这个错误unregister mbean error;tomcat停止运行。目前已经更新为25
这样的问题几年前就修复了,我猜测是你用法的问题,就如同上面这个,不是druid的bug
1年前的问题了
如果是druid自己注册的mbean,会判断重复的,这个显然不是druid的调用栈,是spring-boot注册的
你用的是啥版本啊,早就修复了的
回复
请问这个问题怎样解决?、
这个问题从框架层面应该不难解决,加一个设置项,加一个get方法(没有设置时返回原有的数据源名称)。
早就修复了,druid在高并发下最稳定,这是我们在阿里巴巴/淘宝生产环境中的出来的结论
在我所掌握的数据中,druid是Java语言中最稳定的数据库连接池
回复
@wenshao : 咋解决?
这是druid的bug,druid可以使用mbean管理,而这个东西在jvm了里是全局的,名字不能重复。druid没有考虑这种情况。这里有说明, http://m.blog.csdn.net/blog/lanmo555/41248763,不知道新版本是否已修复。附:我一直不肯druid,其中一个原因就是bug太多了。。
从官网上下的tomcat7.0绿色版,解压开就直接使用了,没有修改里面任何的配置文件。 我刚刚试了一下把两个项目的数据源都换成c3p0启动成功了
tomcat下你怎么部署的?
看到这个错误:javax.management.InstanceAlreadyExistsException:
引用来自“jeffsui”的评论
配置文件,检查下数据源配置
配置文件,检查下数据源配置