What are the differences between c3p0-0.9.1.2
and c3p0-0.9.5
that mean that when I want to register an MBean
with DynamicPooledDataSourceManagerMBean
in 0.9.1.2
everything is okay, but when I use 0.9.5
then com.sun.jmx.mbeanserver.Repository
throws an javax.management.InstanceAlreadyExistsException
.
I use spring as my container so the bean definition for DynamicPooledDataSourceManagerMBean
is like this:
<bean id="register" class="com.mchange.v2.c3p0.management.DynamicPooledDataSourceManagerMBean">
<constructor-arg index="0" ref="dataSource"/>
<constructor-arg index="1" value="my.pool.connection:type=c3p0,name=Main"/>
<constructor-arg index="2" ref="mbeanServer"/>
</bean>
which the dataSource ref definition is a com.mchange.v2.c3p0.ComboPooledDataSource
and defined like this:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" lazy-init="true" >
and a lot of datasource config
and the mbeanSever
is a Spring org.springframework.jmx.support.MBeanServerFactoryBean
which is defined like this:
<bean name="mbeanServer"
class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
<property name="registerWithFactory" value="true"></property>
</bean>
The problem, as @SteveWaldman said, was I tried to register my datasources into MBean server which c3p0 registered them before. So what I should have done was nothing. But there were some modification need to be done to what c3p0 registed. c3p0 register datasource with a name like this:
com.mchange.v2.c3p0:type=PooledDataSource,identityToken=1hgeowz961y14x0ldebkgx|123f9b8,name=Main
I would like to avoid adding identityToken so as said here I create a c3p0.properties file and put this line into it:
com.mchange.v2.c3p0.management.ExcludeIdentityToken=true
That was pretty much everything I had to do for my case. Thanks to @StevenWaldman.