Spring AOP拦截器的序列

Spring AOP 事务不是工作在以下拦截器?
<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>

matchGenericTxInterceptor”事务拦截器,假设来拦截器 urlInterceptorInsert,urlInterceptorCommit,urlInterceptorRelease, 但不能如预期一样工作?

解决

3个拦截器在事务管理器拦截器(matchGenericTxInterceptor)之前执行。
为了解决这个问题,必须改变拦截器 XML文件的顺序,如下面的(把 matchGenericTxInterceptor 放在顶部)。
<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>

注 Spring AOP的拦截器的顺序对功能有影响。


上一篇:Spring AOP实例(Pointcut,Advisor)

下一篇:Spring自动代理创建者实例

关注微信小程序
程序员编程王-随时随地学编程

扫描二维码
程序员编程王

扫一扫关注最新编程教程