`
crud0906
  • 浏览: 134640 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Spring AOP事务简单配置

阅读更多
<tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
             <tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED" />
             <tx:method name="query*" read-only="true" propagation="NOT_SUPPORTED" />
             <tx:method name="find*" read-only="true" propagation="NOT_SUPPORTED" />
   			 <tx:method name="*" rollback-for="Exception" />
        </tx:attributes>
    </tx:advice>
    
    <aop:config proxy-target-class="true">
        <aop:pointcut id="daoMethod"
                      expression="execution(* com.xx.xx.dao.impl..*.*(..))"/>
        <aop:pointcut id="serviceMethod"
        			 expression="execution(* com.xx.xx.service..*.*(..))"/>              
        <aop:advisor pointcut-ref="daoMethod" advice-ref="txAdvice"/>
        <aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice"/>
    </aop:config>

刚开始未加proxy-target-class="true", 启动时候报错:
Bean named 'xxx' must be of type [com.xx.xx.xx.Xxx], but was actually of type [$Proxy73]
注入时候报错,被注入的类(代理过的)不是应该所需的类型,由于提示的这个com.xx.xx.xx.Xxx是一个类,而不是接口(没有采用面向接口编程原则,这里有点不太好),加上proxy-target-class="true"使得spring可以使用cglib对类也可以动态代理,就OK了。
另外,对aop-config中expression表达式进行解释
(* com.xx.xx.dao.impl..*.*(..))
第一个*表示匹配所有类型的返回值
第二个*表示匹配所有的类(前面的..表示impl包及其所有子包)
第三个*表示匹配类中所有的方法
最后括号中..表示匹配方法所有参数
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics