Announcement Announcement Module
Collapse
No announcement yet.
AOP Interceptor with Transactions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP Interceptor with Transactions

    Hello:

    I am pretty sure this topic has already come up, but I looked around the forum and I didn't find anything specific to my issue.

    Our current Spring configuration makes use of the parent attribute of the bean tag:

    <bean id="inquiryService" parent="txProxyTemplate">
    <property name="target">
    <bean class="com.wfs.felix.services.impl.InquiryServiceI mpl">
    <property name="auditTrailService" ref="auditTrailService" />
    <property name="inquiryDao" ref="inquiryDao" />
    <property name="registry" ref="userRegistry" />
    <property name="emailService" ref="emailService" />
    <property name="faxService" ref="faxService" />
    <property name="conversionService" ref="conversionService" />
    <property name="userRegistry" ref="userRegistry" />
    </bean>
    </property>
    </bean>

    However, for the bean referenced above, we now need to add some interceptor functionality via Spring AOP. So the new configuration below:

    <!--The interceptor being used for Audit Trail -->
    <bean id="auditTrailLoggerAdvice" class="com.wfs.felix.aop.interceptors.AuditTrailLo gger">
    <property name="auditTrailService">
    <ref bean="auditTrailService"/>
    </property>
    </bean>

    <!--The pointcut advisor used in Audit Trail. It is based on the method name -->
    <bean id="auditTrailLoggerPointcutAdvisor"
    class="org.springframework.aop.support.NameMatchMe thodPointcutAdvisor">

    <property name="mappedNames">
    <list>
    <value>save</value>
    </list>
    </property>
    <property name="advice">
    <ref bean="auditTrailLoggerAdvice"/>
    </property>
    </bean>

    <bean id="inquiryServiceTarget" class="com.wfs.felix.services.impl.InquiryServiceI mpl">
    <property name="auditTrailService" ref="auditTrailService" />
    <property name="inquiryDao" ref="inquiryDao" />
    <property name="registry" ref="userRegistry" />
    <property name="emailService" ref="emailService" />
    <property name="faxService" ref="faxService" />
    <property name="conversionService" ref="conversionService" />
    <property name="userRegistry" ref="userRegistry" />
    </bean>

    <bean id="inquiryService"
    class="org.springframework.aop.framework.ProxyFact oryBean">

    <!--class="org.springframework.aop.framework.ProxyFact oryBean"-->
    <!--parent="txProxyTemplate"-->

    <property name="proxyInterfaces">
    <value>com.wfs.felix.services.InquiryService</value>
    </property>

    <!--The interceptor for Audit Trail-->
    <property name="interceptorNames">
    <list>
    <value>auditTrailLoggerPointcutAdvisor</value>
    </list>
    </property>

    <property name="target">
    <ref bean="inquiryServiceTarget"/>
    </property>
    </bean>

    As you can see, now we don't have the transaction demarcation in our bean. I know this is possible in Spring and if someone can point me in the right direction I would appreciate it. The book Spring in Action does not as far as I have seen address my issue.

    Thanks in advance,

    Juan A.

  • #2
    However, for the bean referenced above, we now need to add some interceptor functionality via Spring AOP
    Take a look at setPostInterceptors and setPreInterceptors.

    Comment


    • #3
      Originally posted by juan110470
      Our current Spring configuration makes use of the parent attribute of the bean tag:

      <bean id="inquiryService" parent="txProxyTemplate">
      How does the config of txProxyTemplate look like?

      Originally posted by juan110470
      However, for the bean referenced above, we now need to add some interceptor functionality via Spring AOP. [..] As you can see, now we don't have the transaction demarcation in our bean. I know this is possible in Spring and if someone can point me in the right direction I would appreciate it.
      As far as I understand your problem you need to apply the TransactionInterceptor via the ProxyFactoryBean as well. A possible configuration can then look like:

      Code:
      <bean id="inquiryService"
            class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="proxyInterfaces">
          <value>com.wfs.felix.services.InquiryService</value>
        </property>
        <property name="interceptorNames">
          <list>
            <value>auditTrailLoggerPointcutAdvisor</value>
            <value>txInterceptor</value>
          </list>
        </property>
        <property name="target">
          <ref bean="inquiryServiceTarget"/>
        </property>
      </bean>
      
      <bean id="txAttributes"
            class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
        <property name="properties">
          <props>
            <prop key="get*">PROPAGATION_REQUIRED,readOnly,-Exception</prop>
            <prop key="..">..</prop>
          </props>
        </property>
      </bean>
      
      <bean id="txInterceptor"
            class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager" ref="transactionManager"/>
        <property name="transactionAttributeSource" ref="txAttributes"/>
      </bean>

      Comment

      Working...
      X