Results 1 to 3 of 3

Thread: problems switching to @Transactional with AOP

  1. #1
    Join Date
    Aug 2006
    Posts
    7

    Default 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!

  2. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    How about just using
    <tx:annotation-driven/>

    Please see http://static.springframework.org/sp...dvice-settings for more details.

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  3. #3
    Join Date
    Aug 2006
    Posts
    7

    Default

    thanks! that works much better.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •