Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for apache commons-pool2 [SPR-12532] #17137

Closed
spring-issuemaster opened this issue Dec 10, 2014 · 4 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Dec 10, 2014

Anton Antonov opened SPR-12532 and commented

I've tried to upgrade from commons-pool version 1.6 to commons-pool2 version 2.2 and I got the following exception:

Caused by: java.lang.LinkageError: Failed to link org/springframework/aop/target/CommonsPoolTargetSource (Module "deployment.edu-first.war:main" from Service Module Loader)
	at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:428) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.Module.loadModuleClass(Module.java:548) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:189) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.springframework.util.ClassUtils.forName(ClassUtils.java:247) [spring-core-4.0.4.RELEASE.jar:4.0.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395) [spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348) [spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319) [spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
	... 36 more
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool/PoolableObjectFactory
	at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_21]
	at java.lang.ClassLoader.defineClass(ClassLoader.java:791) [rt.jar:1.7.0_21]
	at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:345) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:423) [jboss-modules.jar:1.3.0.Final-redhat-2]
	... 48 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool.PoolableObjectFactory from [Module "deployment.edu-first.war:main" from Service Module Loader]
	at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final-redhat-2]
	at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final-redhat-2]
	... 52 more

Affects: 4.1.3

Referenced from: commits 5e43f9b, e8441ed, aabf73d

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 11, 2014

Stéphane Nicoll commented

Could you please share the configuration that throws that exception?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 11, 2014

Anton Antonov commented

Sure. We’re trying to create a pool of (un)marshallers. With Apache Commons Pool 1.6 it works fine, but when we're trying to move to Apache Commons Pool 2.2, we got the issue I mentioned above. Now we’re using Spring 4.0.4, but with Spring 4.1.3 we have the same issue. The reason is that some classes used in Spring AOP was renamed and changed in Apache Common Pool 2.2.

Here is our set of beans:

    <bean id="jaxbContext" class="javax.xml.bind.JAXBContext" factory-method="newInstance">
        <constructor-arg>
            <list>
                <value type="java.lang.Class">edu.first.jaxb.Example</value>
            </list>
        </constructor-arg>
    </bean>

    <!-- Pool (un)marshallers to improve performance -->
    <bean id="marshallerTarget" class="javax.xml.bind.Marshaller"
          factory-bean="jaxbContext" factory-method="createMarshaller"
          scope="prototype">
    </bean>

    <bean id="unmarshallerTarget" class="javax.xml.bind.Unmarshaller"
          factory-bean="jaxbContext" factory-method="createUnmarshaller"
          scope="prototype">
    </bean>

    <bean id="poolTargetSource" class="org.springframework.aop.target.CommonsPoolTargetSource">
        <property name="targetBeanName" value="marshallerTarget" />
        <property name="maxSize" value="25" />
    </bean>

    <bean id="unmarshallerPoolTargetSource" class="org.springframework.aop.target.CommonsPoolTargetSource">
        <property name="targetBeanName" value="unmarshallerTarget" />
        <property name="maxSize" value="25" />
    </bean>

    <bean id="marshaller" class="org.springframework.aop.framework.ProxyFactoryBean">
        <qualifier value="marshaller" />
        <property name="targetSource" ref="poolTargetSource" />
    </bean>

    <bean id="unmarshaller" class="org.springframework.aop.framework.ProxyFactoryBean">
        <qualifier value="unmarshaller" />
        <property name="targetSource" ref="unmarshallerPoolTargetSource" />
    </bean>
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 18, 2014

Stéphane Nicoll commented

As you found out yourself, we don't support commons-pool2 at all. I have started a quick draft of commons pool2 support in a branch. You can give it a try if you want.

Let's do this for 4.2

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 19, 2015

Stéphane Nicoll commented

Alright, this is implemented. Out of curiosity, what is your use case?

Commons pool 1 is now deprecated in favour of the Commons pool 2 support. It should be noted that commons pool 2 has a major semantic difference as it now rely on the object equality for certain things. So holding two different instances that are equals according to Object#equals will not give the same result.

I have updated our own support to workaround this. Check the Javadoc for more details.

I'd appreciate if you grab a 4.2.0.BUILD-SNAPSHOT and try the new support. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.