java.lang.NoSuchMethodException:com.mchange.v2.c3p0.PoolBackedDataSource.setUserOverridesAsString(java.lang.String)

时间:2009-12-03 15:49:55

标签: java hibernate connection-pooling c3p0

我正在使用C3P0 0.9.1.2为我的连接池配置数据源。

加载上下文时会引发错误。这是跟踪:

java.lang.NoSuchMethodException: com.mchange.v2.c3p0.PoolBackedDataSource.setUserOverridesAsString(java.lang.String)
    at java.lang.Class.getMethod(Class.java:1605)
    at com.mchange.v2.c3p0.cfg.C3P0Config.bindNamedConfigToBean(C3P0Config.java:215)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.initializeNamedConfig(AbstractPoolBackedDataSource.java:89)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.<init>(AbstractPoolBackedDataSource.java:69)
    at com.mchange.v2.c3p0.PoolBackedDataSource.<init>(PoolBackedDataSource.java:37)
    at com.mchange.v2.c3p0.DataSources.pooledDataSource(DataSources.java:267)
    at com.mchange.v2.c3p0.DataSources.pooledDataSource(DataSources.java:246)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:115)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:435)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:903)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:817)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:597)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:366)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:197)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:172)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:158)
    at com.myApp.backoffice.model.CreateSchema.main(CreateSchema.java:8)
java.lang.NoSuchMethodException: com.mchange.v2.c3p0.PoolBackedDataSource.setUserOverridesAsString(java.lang.String)
    at java.lang.Class.getMethod(Class.java:1605)
    at com.mchange.v2.c3p0.cfg.C3P0Config.bindNamedConfigToBean(C3P0Config.java:215)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.initializeNamedConfig(AbstractPoolBackedDataSource.java:89)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.<init>(AbstractPoolBackedDataSource.java:69)
    at com.mchange.v2.c3p0.PoolBackedDataSource.<init>(PoolBackedDataSource.java:37)
    at com.mchange.v2.c3p0.DataSources.pooledDataSource(DataSources.java:267)
    at com.mchange.v2.c3p0.DataSources.pooledDataSource(DataSources.java:246)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:115)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:435)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:903)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:817)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:197)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:172)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:158)
    at com.myApp.backoffice.model.CreateSchema.main(CreateSchema.java:8)
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaCreator' defined in class path resource [CreateSchema.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for property 'sessionFactory'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for property 'sessionFactory': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:197)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:172)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:158)
    at com.myApp.backoffice.model.CreateSchema.main(CreateSchema.java:8)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for property 'sessionFactory'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for property 'sessionFactory': no matching editors or conversion strategy found
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1249)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    ... 15 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for property 'sessionFactory': no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:219)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
    ... 19 more

我搜索了这个问题,但我什么都没发现。任何的想法? 有谁知道c3p0中是否有任何错误?

&LT;&LT;在12月10日添加&gt;&gt; 以下是我的Spring XML配置文件中最相关的部分:

<!-- Driver Register -->
<bean id="systemProperties" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetClass"> 
        <value>java.lang.System</value>
    </property>
    <property name="targetMethod">
        <value>setProperty</value>
    </property>
    <property name="arguments">
        <list>
            <value>jdbc.drivers</value>
            <value>${jdbc.driverClassName}</value>
        </list>
    </property>
</bean>

<bean id="unpooledRODataSource"
    class="com.mchange.v2.c3p0.DataSources"
    factory-method="unpooledDataSource">
    <constructor-arg value="${jdbc.ro.url}"/>
    <constructor-arg value="${jdbc.ro.username}"/>
    <constructor-arg value="${jdbc.ro.password}"/>
</bean>

<bean id="unpooledRWDataSource" 
    class="com.mchange.v2.c3p0.DataSources"
    factory-method="unpooledDataSource">
    <constructor-arg value="${jdbc.rw.url}"/>
    <constructor-arg value="${jdbc.rw.username}"/>
    <constructor-arg value="${jdbc.rw.password}"/>
</bean>

<bean id="pooledRODataSource" 
    class="com.mchange.v2.c3p0.DataSources"
    factory-method="pooledDataSource">
    <constructor-arg ref="unpooledRODataSource"/>
    <constructor-arg value="readonly"/>
</bean>

<bean id="pooledRWDataSource" 
    class="com.mchange.v2.c3p0.DataSources"
    factory-method="pooledDataSource">
    <constructor-arg ref="unpooledRWDataSource"/>
    <constructor-arg value="readwrite"/>
</bean>

<alias name="pooledRWDataSource" alias="dataSource"/>
<alias name="pooledRODataSource" alias="alternativeDataSource"/>

<bean id="sessionFactory" 
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="hibernateProperties">
        <props>
            <!-- values from properties file -->
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
            <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
            <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
            <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
            <prop key="hibernate.validator.apply_to_ddl">${hibernate.validator.apply_to_ddl}</prop>
            <prop key="hibernate.validator.autoregister_listeners">${hibernate.validator.autoregister_listeners}</prop>
        </props>
    </property>
    <property name="dataSource" ref="dataSource"/>
    <!-- using classpath scanning for autodetection of entity classes (when >= spring 2.5.6) -->
    <property name="packagesToScan">
        <list>
            <value>com/myApp/backoffice/model/*/dto/</value>
        </list>
    </property>
    <property name="eventListeners">
        <map>
            <entry key="merge">
                <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
            </entry>
        </map>
    </property>
    <property name="entityInterceptor" ref="backofficeInterceptor"/>
</bean>

<!-- Transaction manager -->
<bean id="transactionManager" class="com.myApp.persistence.tx.impl.TransactionManagerImpl">
    <property name="timeoutDelayInMillis" value="${session.timeout}"/>
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Transactional interceptor -->
<bean id="transactionalInterceptor"
    class="com.myApp.persistence.tx.impl.TransactionalInterceptor">
    <property name="transactionManager" ref="transactionManager" />
</bean>
<!-- Assign Transactional interceptor to @Transactional methods -->
<bean class="com.myApp.persistence.tx.TransactionalAutoProxyCreator">
    <property name="transactionalInterceptor" ref="transactionalInterceptor" />
</bean>

2 个答案:

答案 0 :(得分:1)

看起来你正在使用Spring。可能是你的Spring XML配置不正确,所以如果你可以发布相关位,这将有所帮助。

Class PoolBackedDataSource 显然没有 setUserOverridesAsString 方法。也许你想要类 ComboPooledDataSource

答案 1 :(得分:1)

听起来你正在使用旧版本或更新版本的c3p0 jar(常用于Hibernatequartz)而不是预期...尝试确保所有依赖项都是得到满足。