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的攔截器的順序對功能有影響。