PDA

View Full Version : HotSwappableTargetSource problem with Spring >= 1.1.2


calvin
Dec 7th, 2004, 02:43 PM
I've used a HotSwappableTargetSource successfully since before 1.1.1, but encounter a problem upon upgrading to Spring 1.1.2 in order to fix another issue.

My application context for the relevant beans is as follows:

<bean id="swapper" class="org.springframework.aop.target.HotSwappableTargetS ource">
<constructor-arg><ref local="appXaDataSource"/></constructor-arg>
</bean>
<bean id="swappable" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="targetSource">
<ref local="swapper"/>
</property>
</bean>
<bean id="appXaDataSource"
class="org.enhydra.jdbc.standard.StandardXADataSource" singleton="false" destroy-method="shutdown"/>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate.LocalSessionFact oryBean" lazy-init="true">
<description>Lazy-loading session factory.</description>
<property name="dataSource">
<ref local="swappable"/>
</property>
<property name="mappingResources">
<list>
<value>hbm/ApplicationModel.hbm.xml</value>
<!-- ... -->
</list>
</property>
<property name="hibernateProperties">
<ref local="hibernateProperties"/>
</property>
<property name="entityInterceptor">
<ref local="dependencyInjectionInterceptor"/>
</property>
<property name="jtaTransactionManager">
<ref local="jotm"/>
</property>
</bean>

In Spring 1.1.1, this works fine and reliably, but in Spring 1.1.2 (and I verified that the problem remains with today's CVS build), I get the following error:

org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'com.thatone.archie.persistence.ArchieHibernateDao ' defined in file [/home/calvins/Desktop/workspace/fud/build/archie/WEB-INF/applicationContext.xml]: Can't resolve reference to bean 'sessionFactory' while setting property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in file [/home/calvins/Desktop/workspace/fud/build/archie/WEB-INF/applicationContext.xml]: Can't resolve reference to bean 'swappable' while setting property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'swappable' defined in file [/home/calvins/Desktop/workspace/fud/build/archie/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.aopalliance.aop.AspectException: null
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in file [/home/calvins/Desktop/workspace/fud/build/archie/WEB-INF/applicationContext.xml]: Can't resolve reference to bean 'swappable' while setting property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'swappable' defined in file [/home/calvins/Desktop/workspace/fud/build/archie/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.aopalliance.aop.AspectException: null
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'swappable' defined in file [/home/calvins/Desktop/workspace/fud/build/archie/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.aopalliance.aop.AspectException: null
net.sf.cglib.core.CodeGenerationException: java.lang.ClassCastException-->null
at net.sf.cglib.core.ReflectUtils.newInstance(Reflect Utils.java:235)
at net.sf.cglib.core.ReflectUtils.newInstance(Reflect Utils.java:220)
at net.sf.cglib.core.ReflectUtils.newInstance(Reflect Utils.java:216)
at net.sf.cglib.proxy.Enhancer.createUsingReflection( Enhancer.java:566)
at net.sf.cglib.proxy.Enhancer.firstInstance(Enhancer .java:493)
at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:220)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer. java:368)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:2 80)
at org.springframework.aop.framework.Cglib2AopProxy.g etProxy(Cglib2AopProxy.java:163)
at org.springframework.aop.framework.Cglib2AopProxy.g etProxy(Cglib2AopProxy.java:124)
at org.springframework.aop.framework.ProxyFactoryBean .getSingletonInstance(ProxyFactoryBean.java:233)
at org.springframework.aop.framework.ProxyFactoryBean .setBeanFactory(ProxyFactoryBean.java:197)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:271)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:240)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveReference(Abstra ctAutowireCapableBeanFactory.java:898)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveValueIfNecessary (AbstractAutowireCapableBeanFactory.java:832)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:773)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:601)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:258)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:240)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveReference(Abstra ctAutowireCapableBeanFactory.java:898)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveValueIfNecessary (AbstractAutowireCapableBeanFactory.java:832)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:773)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:601)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:258)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveInnerBeanDefinit ion(AbstractAutowireCapableBeanFactory.java:858)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveValueIfNecessary (AbstractAutowireCapableBeanFactory.java:823)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:773)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:601)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:258)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:240)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:476)
at com.thatone.archie.config.ApplicationConfiguration .getDao(ApplicationConfiguration.java:140)
at com.thatone.archie.config.ApplicationConfiguration .getDataSourceById(ApplicationConfiguration.java:4 54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:295)
at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:154)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :121)
at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:56)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :143)
at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy0.getDataSourceById(Unknown Source)
at com.thatone.archie.engine.task.SimpleTaskHelperImp lTest.setUp(SimpleTaskHelperImplTest.java:46)
at junit.framework.TestCase.runBare(TestCase.java:125 )
at junit.framework.TestResult$1.protect(TestResult.ja va:106)
at junit.framework.TestResult.runProtected(TestResult .java:124)
at junit.framework.TestResult.run(TestResult.java:109 )
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:186)
Caused by: java.lang.ClassCastException
at org.enhydra.jdbc.standard.StandardXADataSource$$En hancerByCGLIB$$2b71cd79_2$$FastClassByCGLIB$$68f36 b1e.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodP roxy.java:167)
at org.springframework.aop.framework.Cglib2AopProxy$A bstractInterceptor.doInvoke(Cglib2AopProxy.java:34 2)
at org.springframework.aop.framework.Cglib2AopProxy$D ynamicUnadvisedInterceptor.intercept(Cglib2AopProx y.java:414)
at org.enhydra.jdbc.standard.StandardXADataSource$$En hancerByCGLIB$$2b71cd79_2.setLogger(<generated>)
at org.enhydra.jdbc.standard.StandardDataSource.<init>(StandardDataSource.java:68)
at org.enhydra.jdbc.standard.StandardConnectionPoolDa taSource.<init>(StandardConnectionPoolDataSource.java:46)
at org.enhydra.jdbc.standard.StandardXADataSource.<init>(StandardXADataSource.java:70)
at org.enhydra.jdbc.standard.StandardXADataSource$$En hancerByCGLIB$$2b71cd79_2.<init>(<generated>)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:274)
at net.sf.cglib.core.ReflectUtils.newInstance(Reflect Utils.java:228)
... 63 more



I've checked the release notes for 1.1.2, and have searched the forums and jira, but did not find anything helpful.

Does anybody know what might have changed between 1.1.1 and 1.1.2 that could cause this behavior?

Thanks for any information....

-calvin

robh
Dec 8th, 2004, 09:42 AM
Calvin,

I'm going to look into this a bit more. The only thing that changed between 1.1.1 and 1.1.2 in this class was that we added a partial workaround to a problem in CGLIB that causes bean state to be reset to any default values set by the constructor. As it turns out we can't completely fix this problem in Spring and we are awaiting a fix in CGLIB.

You problem seems to lie somewhere near the modified code. I will update this topic when I know more.

Rob

robh
Dec 8th, 2004, 10:21 AM
Calvin,

I have found the problem you are experiencing and I have raised an issue in JIRA (SPR-529). I will be committing a fix to CVS today which should make it into the 1.1.3 release in the next few days.

I apologize for any problems you have encoutered related to this issue.

Rob

calvin
Dec 8th, 2004, 12:34 PM
Thanks, Rob. That's great news. I'll be watching for the commit in CVS. If you are able to update this thread when you commit, that would be wonderful, as I'll get an email notification and can build from CVS immediately.

Thanks again...

-calvin

calvin
Dec 8th, 2004, 03:07 PM
Got the update from CVS and verified that I'm back in Spring nirvana again.

Thanks very much for taking care of this so quickly.