← 返回列表

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> </proper

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的拦截器的顺序对功能有影响。


打开资源 ↗

交流与评论