PDA

View Full Version : CommonsPoolTargetSource and Constructor Injection



wrk
Feb 24th, 2005, 01:37 PM
I am attempting to use CommonsPoolTargetSource to manage instances of an object that expects a Properties object passed to the constructor, then apply ProxyFactoryBean to enable pooling within my application. I am working with Spring Framework 1.1.3.

Here is the definition of the target:

<bean id="delegateTarget" class="wrk.DirectoryInquiryDelegate" singleton="false">
<constructor-arg>
<props>
<prop key="java.naming.provider.url">$&#123;java.naming.provider.url&#125;</prop>
<prop key="java.naming.security.principal">$&#123;java.naming.security.principal&#125;</prop>
<prop key="java.naming.security.credentials">$&#123;java.naming.security.credentials&#125;</prop>
</props>
</constructor-arg>
</bean>


Here is the declaration for the target source:

<bean id="poolTargetSource" class="org.springframework.aop.target.CommonsPoolTargetSo urce">
<property name="targetBeanName"><value>delegateTarget</value></property>
<property name="maxSize"><value>5</value></property>
</bean>


And finally, here is the proxy factory:

<bean id="delegate" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="targetSource"><ref local="poolTargetSource"/></property>
</bean>


Everything seems to be ok right up to the point of initializing the proxy, at which point the following exception is thrown:

org.springframework.beans.factory.BeanCreationExce ption&#58; Error creating bean with name 'delegate' defined in class path resource &#91;csilContext.xml&#93;&#58; Initialization of bean failed; nested exception is org.aopalliance.aop.AspectException&#58; null
java.lang.IllegalArgumentException&#58; Superclass has no null constructors but no arguments were given
at net.sf.cglib.proxy.Enhancer.emitConstructors&#40;Enhan cer.java&#58;783&#41;
at net.sf.cglib.proxy.Enhancer.emit&#40;Enhancer.java&#58;749 &#41;
at net.sf.cglib.proxy.Enhancer.generateClass&#40;Enhancer .java&#58;481&#41;
at net.sf.cglib.transform.TransformingClassGenerator. generateClass&#40;TransformingClassGenerator.java&#58;33&#41;
at net.sf.cglib.core.DefaultGeneratorStrategy.generat e&#40;DefaultGeneratorStrategy.java&#58;25&#41;
at net.sf.cglib.core.AbstractClassGenerator.create&#40;Ab stractClassGenerator.java&#58;215&#41;
at net.sf.cglib.proxy.Enhancer.createHelper&#40;Enhancer. java&#58;368&#41;
at net.sf.cglib.proxy.Enhancer.create&#40;Enhancer.java&#58;2 80&#41;
at org.springframework.aop.framework.Cglib2AopProxy.g etProxy&#40;Cglib2AopProxy.java&#58;163&#41;
at org.springframework.aop.framework.Cglib2AopProxy.g etProxy&#40;Cglib2AopProxy.java&#58;124&#41;
at org.springframework.aop.framework.ProxyFactoryBean .getSingletonInstance&#40;ProxyFactoryBean.java&#58;241&#41;
at org.springframework.aop.framework.ProxyFactoryBean .setBeanFactory&#40;ProxyFactoryBean.java&#58;201&#41;
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean&#40;AbstractAuto wireCapableBeanFactory.java&#58;301&#41;


It is distinctly possible that I have misunderstood the configuration requirements for the use of the Commons Pool Target Source but I can't seem to figure out what I am doing wrong.

Any advice would be greatly appreciated!

irbouho
Feb 24th, 2005, 08:17 PM
Is this related to Cannot proxy classes lacking no-arg constructor using CGLIB (http://opensource.atlassian.com/projects/spring/browse/SPR-285)?