Announcement Announcement Module
Collapse
No announcement yet.
JavaConfig: Replacing aop:advisor and tx:advice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JavaConfig: Replacing aop:advisor and tx:advice

    Hi,

    I'm wondering if I can map this piece of xml-configuration to Spring JavaConfig:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:aop="http://www.springframework.org/schema/aop" 
      xmlns:tx="http://www.springframework.org/schema/tx" 
      xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schem...ring-beans.xsd
                          http://www.springframework.org/schema/aop     http://www.springframework.org/schem...spring-aop.xsd
                          http://www.springframework.org/schema/tx      http://www.springframework.org/schema/tx/spring-tx.xsd"
      default-autowire="byName">
    
      <aop:config>
         <aop:pointcut id="serviceAnnotatedClass" expression="@within(org.springframework.stereotype.Service)" />
         <aop:advisor id="managerTx" advice-ref="txAdvice" pointcut-ref="serviceAnnotatedClass" order="20" />
      </aop:config>
    
      <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
          <tx:method name="get*" read-only="true" />
          <tx:method name="find*" read-only="true" />
          <tx:method name="load*" read-only="true" />
          <tx:method name="is*" read-only="true" />
          <tx:method name="ownTransaction*" propagation="REQUIRES_NEW" rollback-for="Exception" />
          <tx:method name="*" rollback-for="Exception" />
        </tx:attributes>
      </tx:advice>
    
    </beans>
    So far I figured out how to replace aop:pointcut with
    Code:
    <aop:advisor id="managerTx" advice-ref="txAdvice" 
    pointcut="com.myapp.configuration.AspectConfig.serviceAnnotatedClass()" order="20"/>
    and
    Code:
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Pointcut;
    
    @Aspect
    public class AspectConfig
    {
    
      @Pointcut("@within(org.springframework.stereotype.Service)")
      public void serviceAnnotatedClass() {}
    
    }
    Any hints how to replace the rest?

    Jonny
    Last edited by jonnybecker; Jan 2nd, 2013, 06:58 AM.
Working...
X