ERROR c.a.d.s.DruidDataSourceStatManager - unregister mbean error javax.management.InstanceNotFoundE

启动tomcat后报错

ERROR c.a.d.s.DruidDataSourceStatManager - unregister mbean error
javax.management.InstanceNotFoundException: com.alibaba.druid:type=DruidDataSourceStat
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1095)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.exclusiveUnregisterMBean(DefaultMBeanServerInterceptor.java:427)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.unregisterMBean(DefaultMBeanServerInterceptor.java:415)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.unregisterMBean(JmxMBeanServer.java:546)
	at com.alibaba.druid.stat.DruidDataSourceStatManager.removeDataSource(DruidDataSourceStatManager.java:209)
	at com.alibaba.druid.pool.DruidDataSource$2.run(DruidDataSource.java:2132)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.alibaba.druid.pool.DruidDataSource.unregisterMbean(DruidDataSource.java:2128)
	at com.alibaba.druid.pool.DruidDataSource.close(DruidDataSource.java:2085)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:339)
	at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:273)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:587)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:559)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1092)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:520)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1085)
	at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1061)
	at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1030)
	at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:949)
2021-10-09 11:44:14 [SpringContextShutdownHook] ERROR c.a.druid.stat.DruidStatService - unregister mbean error

解决的办法:修改tomcat bin 下面的 catalina.sh

#OS specific support.  $var _must_ be set to either true or false.

cygwin=false中间加入
JAVA_OPTS="-Ddruid.registerToSysProperty=true"
也就是这样

# OS specific support.  $var _must_ be set to either true or false.
JAVA_OPTS="-Ddruid.registerToSysProperty=true"
cygwin=false

重新启动

造成这个错误的原因,大概是因为在注册MBean时,一定要保证id的唯一,服务器上边tomcat有多个,并且都是用的druid。
参考网址:

https://blog.csdn.net/huanxue517/article/details/51888507

但是,我发现我的并没有什么用,后来发现是因为我用tomcat启动的时候重复启动了两次,
解决方法:
修改tomcat中的server.xml,

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
	<Context docBase="test" path="" reloadable=""/>

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
	<Context docBase="test" path="" reloadable="" name="/test" />

增加了name属性,Tomcat首先根据Context的配置内容生成第一个StandardContext对象,加载一次项目。然后再根据Host/appBase的配置对webapps下面的项目(test)生成第二个StandardContext,再加载一次项目。Tomcat针对同一项目生成两个StandardContext的原因就是因为他们的名字不同,Tomcat认为是两个Context,所以加载了两次。而他们的名字是谁决定的呢?第一个StandardContext的名字是由标签:Context的配置来决定的,而第二个StandardContext的名字是由项目名称(test)决定的。
参考链接:

https://blog.csdn.net/lmmzsn/article/details/77990538

至此,已经解决了第一个问题,顺便还解决了我定时任务重复加载导致错误的问题: Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally,如果你的定时任务突然不运行了,并且没有报什么错,可以看一下qrtz_scheduler_state 这个数据库表,如果里边的数据超过一条,说明有其他的用户也在用,我这个数据库只有一个连接者,但是居然报错了,发现是自己的tomcat启动了多次

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值