NoClassDefFoundError: org/apache/commons/pool/KeyedObjectPoolFactory BasicDataSource Spring

做~自己de王妃 提交于 2019-12-01 16:44:29

问题


I'm new to Spring, still learning. I'm using Spring Tool Suite version 3.5 with Java 6 on my Mac. I'm attempting to use BasicDataSource

<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>

I have the following jar files on my class path: commons-dbcp-1.4.jar, commons-pool2-2.2.jar, commons-collections4-4.0.jar. But I'm still seeing a NoClassDefFoundError reference to KeyedObjectPoolFactory.

Error creating bean with name 'dataSource' defined in class path resource [test-   infrastructure-config.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedObjectPoolFactory
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:630)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)

I've searched for an answer and found an existing similar question, but unlike that one, I've got the JARs on my classpath.

I have trouble formatting code in this forum. My XML code isn't appearing. Sorry.


回答1:


You're mixing up the versions. The KeyedObjectPoolFactory class exists in the 1.x branch of commons-pool, but not in 2.x. You should try with commons-pool-1.5.4 instead (which is the correct version dependency for commons-dbcp-1.4)

And may I suggest using eg. Maven to manage your dependencies - you'll get the transitive dependencies versioned correctly for free (mostly at least...)

Cheers,



来源:https://stackoverflow.com/questions/23654382/noclassdeffounderror-org-apache-commons-pool-keyedobjectpoolfactory-basicdataso

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!