Migration to Tomcat 8: InstanceAlreadyExistsException datasource

时光怂恿深爱的人放手 提交于 2019-12-03 04:34:20
Radi Radichev

We had the same problem. We declared our data source as a spring bean, and it looks like both spring and the bean itself try to register an Mbean which leads to this conflict. All we had to do is configure our Mbean Exporter like this:

@Bean
public AnnotationMBeanExporter annotationMBeanExporter() {
    AnnotationMBeanExporter annotationMBeanExporter = new AnnotationMBeanExporter();
    annotationMBeanExporter.addExcludedBean("dataSource");
    return annotationMBeanExporter;
}

Although I suppose setting the registration policy to:

annotationMBeanExporter.setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);

might also work.

I had the same error and resolved it by adding registration="ignoreExisting" to the mbean-export part:

<context:mbean-export server="mbeanServer" default-domain="mydomain" registration="ignoreExisting" />

If you want the solution using annotations Spring boot already defines MBeanExporter bean so you can auto-wire on it

@Autowired
MBeanExporter mBeanExporter ;

Then change the registration policy

mBeanExporter.setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);

If anybody uses applicationContext.xml style out there, I solved the issue like this:

<bean id="myNamedExporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="registrationPolicy" value="IGNORE_EXISTING" />
</bean>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!