JAVA后台开发_从入门到精通

33 Spring AOP拦截器的序列

2017-08-24  本文已影响14人  笑Skr人啊

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>

上一篇下一篇

猜你喜欢

热点阅读