Main Tutorials

Spring AOP Interceptor transaction is not working

Problem

The Spring AOP transaction is not working in following interceptors?


 <bean id="testAutoProxyCreator"
    class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
	<property name="interceptorNames">
		<list>
			<idref bean="urlInterceptorInsert" />
			<idref bean="urlInterceptorCommit" />
			<idref bean="urlInterceptorRelease" />
			<idref bean="matchGenericTxInterceptor" />
		</list>
	</property>
	<property name="beanNames">
		<list>
			<idref local="urlBo" />
		</list>
	</property>
</bean>

The “matchGenericTxInterceptor” transaction interceptor, suppose to intercept urlInterceptorInsert, urlInterceptorCommit,urlInterceptorRelease, but it’s not work as expected?

Solution

The 3 interceptors are executed before transaction manager interceptor (matchGenericTxInterceptor).

To fix it, you have to change the sequence of the interceptor xml file like following (put matchGenericTxInterceptor on top).


 <bean id="testAutoProxyCreator"
        class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
	<property name="interceptorNames">
		<list>
            <idref bean="matchGenericTxInterceptor" />
			<idref bean="urlInterceptorInsert" />
			<idref bean="urlInterceptorCommit" />
			<idref bean="urlInterceptorRelease" />
		</list>
	</property>
	<property name="beanNames">
		<list>
			<idref local="urlBo" />
		</list>
	</property>
</bean>
Note
The sequence of Spring AOP interceptors do affect the functionality.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
manish
11 years ago

Really wonderful Tutorials..Keep it up..

phuongnamvu
11 years ago

My mkyong is my KING !!!

ravi
13 years ago

Its amazing website for the beginners…

Thanks a lot for your contribution..

Regards,
Ravi Beli