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

I'm new to Spring, still learning. I am using Spring Tool Suite version 3.5 with Java 6 on my Mac. I am trying 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 in my class path: commons-dbcp-1.4.jar , commons-pool2-2.2.jar , commons-collections4-4.0.jar . But I still see the NoClassDefFoundError link 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 searched for an answer and found an existing similar question , but in contrast, I have a JAR in my classpath.

I am having trouble formatting the code in this forum. My xml code is not displayed. Unfortunately.

+6
source share
1 answer

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

And I can suggest using, for example. Maven to manage your dependencies - you will get the correct transitional dependency versions for free (basically, at least ...)

Greetings

+6
source

All Articles