美文网首页
Spring使用笔记

Spring使用笔记

作者: 柳岸花开 | 来源:发表于2017-10-20 11:04 被阅读65次

    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
      注意:proxy-target-class属性值决定是基于接口的还是基于类的代理被创建。如果proxy-target-class 属性值被设置为true,那么基于类的代理将起作用(这时需要cglib库)。如果proxy-target-class属值被设置为false或者这个属性被省略,那么标准的JDK 基于接口的代理将起作用。JDK只能对于接口进行做代理。如果换成类的话,则会抛Java.lang.ClassCastException异常。

    即使你未声明 proxy-target-class="true" ,但运行类没有继承接口,spring也会自动使用CGLIB代理。

    高版本spring自动根据运行类选择 JDK 或 CGLIB 代理

    aop:config proxy-target-class="true">
    <aop:aspect id="dataSourceAspect" ref="dataSourceInterceptor">
    <aop:pointcut id="dao" expression="execution(* com.itrus.portal.service.*.*(..))" />
    <aop:before pointcut-ref="dao" method="setDataSource" />
    </aop:aspect>
    <aop:aspect id="dataSourceAspect0" ref="dataSourceInterceptor">
    <aop:pointcut id="daoLog" expression="execution(* com.itrus.portal.utils.Log.*(..))" />
    <aop:before pointcut-ref="daoLog" method="setDataSourceLog" />
    </aop:aspect>
    <aop:aspect id="controllerAop" ref="controllerAop">
    <aop:pointcut id="target" expression="execution(public com.itrus.portal.controller.ResultBean *(..))" />
    <aop:around method="handlerControllerMethod" pointcut-ref="target" />
    </aop:aspect>
    </aop:config>

    相关文章

    网友评论

        本文标题:Spring使用笔记

        本文链接:https://www.haomeiwen.com/subject/svutrxtx.html