problems switching to @Transactional with AOP
Followed the online reference and did the following:
Code:
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor" ref="txInterceptor"/>
</bean>
<bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="myTransactionManager"/>
<property name="transactionAttributeSource">
<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
</property>
</bean>
Then annotated one service class with @Transactional.
What I was expecting was for DefaultAdvisorAutoProxyCreator to create a proxy only for my one class that is annotated with @Transactional but it seems to be creating proxies for every bean which is causing problems like:
Code:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'someOtherServiceTarget' defined in file [applicationContext-common-service.xml]:
Initialization of bean failed;
nested exception is org.springframework.beans.TypeMismatchException:
Failed to convert property value of type [$Proxy29]
to required type [MyDAOImpl] for property 'myDaoInterface';
nested exception is java.lang.IllegalArgumentException:
Cannot convert value of type [$Proxy29] to required
type [MyDAOImpl] for property 'myDaoInterface':
no matching editors or conversion strategy found
Then I tried adding: <property name="proxyTargetClass" value="true"/> to DefaultAdvisorAutoProxyCreator. And get an error because a proxy cannot be created for hibernate SessionFactoryImpl.
Code:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'defaultWebSessionFactory':
Post-processing of the FactoryBean's object failed; nested exception is
org.springframework.aop.framework.AopConfigException:
Could not generate CGLIB subclass of class
[class org.hibernate.impl.SessionFactoryImpl]:
Common causes of this problem include using a final class or
a non-visible class; nested exception is java.lang.IllegalArgumentException:
Cannot subclass final class class org.hibernate.impl.SessionFactoryImpl
The questions I have are, why is every bean being proxied? and how can I get this to work?
Thanks in advance for any help!