Announcement Announcement Module
No announcement yet.
TransactionProxyFactoryBean interception Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • TransactionProxyFactoryBean interception

    I'm working on a cacheing mechanism for a Spring/Hibernate/Struts based application. All access to the DAO layer is via a service facade, using TransactionProxyFactoryBean, so I'd have something like this for each "subject area":

    <bean id="organisationService" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref local="transactionManager"/>
    <property name="transactionAttributes">
    <prop key="store*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <property name="target">
    <ref local="organisationServiceTarget"/>

    <bean id="organisationServiceTarget" class="mypackage.service.OrganisationServiceImpl">
    <property name="organisationDAO">
    <ref local="organisationDAO"/>

    <bean id="organisationDAO" parent="baseDAO" class="mypackage.dao.organisation.HibernateOrganis ationDAO"/>

    Now, I want to throw cacheing into the mix - purging the cache when certain methods are used, checking and perhaps using the content of the cache when other methods are used. My first attempt used BeanNameAutoProxyCreator to allow me to apply my interceptor to all relevant beans, but I found that if I match *Service, the only method that gets intercepted is the getObject method of the TransactionProxyFactoryBean, NOT the methods of the proxied object. Changing this to *ServiceTarget (i.e, the objects themselves) gets the right methods called.

    But I'm wondering whether this is the right approach at all. Should I be adding stuff into the configuration of the service beans themselves instead, namely PreInterceptors or PostInterceptors for the TransactionProxyFactoryBean, or perhaps specifying a MethodPointcut for the TransactionInterceptor?

  • #2
    Autoproxying or pre- or post-interceptors should work. I would probably incline to the latter approach, with a base template, as it's a bit more convenient.

    Note that you can use autowiring with TransactionProxyFactoryBean if you use an "inner bean" for the target, instead of the X/XTarget approach.


    • #3
      Thanks, Rod, I'll look into those options. And thanks, too, for Spring itself, a fabulous piece of work.