Spring Annotation driver Transaction with AspectJ

2019-07-08 22:19发布

问题:

i am using AspectJ compile time weaving and spring 3.O. and Hibernate 3.0...AspectJ weaving is working fine for simple things like logging but this is not working correctly for Transaction

<tx:annotation-driven transaction-manager="transactionManager"
    mode="aspectj" order="1" />
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
</bean>

Sprong-aspects jar is also present in the lib forlder but still transactional support is not working..

i am using like this

@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void invokeService() throws Exception {
    insertUpdatePolicy();
}

logging doesn,t specify any transactions..transactions are working fine with spring aop but not with aspectj when the class is not defined in the spring container

回答1:

Please post the actual code that is failing.

Enable logging. Check the logs to see if transactions are even being managed at all. If they are, then there is probably an issue with how you configured the transactions.



回答2:

i have found answer to this problem,

One thing we need to keep in mind that we need to place spring-aspects.jar to my Aspect Path instead of java class path.otherwise weaving is not done and transaction is not working.

Second thing i was missing following configuration in spring=bean config.

<bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect" factory-method="aspectOf">
<property name="transactionManager" ref="transactionManager"/>