码迷,mamicode.com
首页 > 编程语言 > 详细

Spring AOP

时间:2020-03-02 11:00:04      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:config   only   methods   int   www   version   tar   att   ref   

配置参考:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="find*" read-only="true" />
            <tx:method name="query*" read-only="true" />
            <tx:method name="get*" read-only="true" />
            <tx:method name="*" />
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut expression="execution(* org.mx..dao.I*Dao.*(..))"
            id="daoMethods" />
        <aop:pointcut expression="execution(* org.mx..task.I*Task.*(..))"
            id="taskMethods" />
        <aop:pointcut expression="execution(* com.business..I*Business.*(..))"
            id="businessMethods" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="taskMethods" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="businessMethods" />
        <aop:aspect id="LogAspect" ref="LogAspectBean">
            <aop:pointcut expression="execution(* org.mx..task.I*Task.*(..))"
                id="logsPointCut" />
            <aop:pointcut expression="execution(* com.business.I*Business.*(..))"
                id="logsPointCutBusiness" />
            <aop:around pointcut-ref="logsPointCut" method="businessLogAround" />
            <aop:around pointcut-ref="logsPointCutBusiness" method="businessLogAround" />
        </aop:aspect>
    </aop:config>
</beans>

 

Spring AOP

标签:config   only   methods   int   www   version   tar   att   ref   

原文地址:https://www.cnblogs.com/Alwaysbecoding/p/12393864.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!