0
votes

I've got some trouble while configuring spring transaction manager. The application I'm working on has a layered architecture. Therefore it has a service layer containing all the transactional services. I wanted for spring to rollback the transaction when a checked (application specific) exception has occurred. I succeeded doing that by annotation as follows:

@Transactional(value="transactionDds", rollbackfor="Throwable")

This works fine. But since I've so many services hence I want to move this configuration to XML (spring DAO context file). This is what I've done:

<tx:advice id="txAdvice" transaction-manager="transactionManagerDds">
    <tx:attributes>
        <tx:method name="*" read-only="false" propagation="REQUIRED" rollback-for="Throwable"/>
    </tx:attributes>
 </tx:advice>
 <aop:config>
    <aop:pointcut id="transRollbackOp" expression="execution(*fr.def.iss.ult.moduleManagement.service.dds.*.*.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="transRollbackOp"/>
  </aop:config> 

  <bean id="transactionManagerDds" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
     <property name="dataSource" ref="beanDataSourceFactory" />  
      <qualifier value="transactionDds"/> 
  </bean>

So basically, I'va a transaction manager which is associated to an advice which rolls back for the possible methods when a Throwable exception occurs. And this advice is linked to an AOP config that way we specify all the interfaces in the service layer of application on which this transaction configuration is to be applied. But this doesn't work. Transaction doesn't roll back Throwable exception occurs. I don't understand that this works with annotation but not with declarative configuration in XML.

I'm really looking forward for your suggestions. I'm totally blocked. Plz help me out. Thanx in advance.

1
For starters first fix your expression it is missing a space between *fr.def should be * fr.def. Also instead of *.*.* it is easier to write ..*.* this catches all classes in subpackages regardless of depth. in short write execution(* fr.def.iss.ult.moduleManagement.service.dds..*.*(..)) instead of what you have now. And make sure it is in the context file in which you had <tx:annotation-driven />M. Deinum
Thanx for your response. I works fine now. Certainly I had problem with my expression.Himanshu ARORA

1 Answers

0
votes
<aop:config>
    <aop:pointcut id="transRollbackOp" expression="execution(*fr.def.iss.ult.moduleManagement.service.dds.*.*.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="transRollbackOp"/>
</aop:config>

In your <aop:config /> the expression you entered is invalid. It should at least contain a whitespace between * and fr.def.

Next instead of .*.*.* I suggest writing ..*.* which selects all classes in all subpackages regardless of depth.

In short change your expression to execution(* fr.def.iss.ult.moduleManagement.service.dds..*.*(..)) should make it work.