zoukankan      html  css  js  c++  java
  • 【spring源码分析】面向切面编程架构设计

    2 注解说明

    2.1 @Aspect

    作用是把当前类标识为一个切面供容器读取

    2.2 @Before
    标识一个前置增强方法,相当于BeforeAdvice的功能,相似功能的还有

    2.3 @AfterReturning

    后置增强,相当于AfterReturningAdvice,方法正常退出时执行

    2.4 @AfterThrowing

    异常抛出增强,相当于ThrowsAdvice

    2.5 @After

    final增强,不管是抛出异常或者正常退出都会执行

    2.6 @Around

    环绕增强,相当于MethodInterceptor

    2.7 @DeclareParents

    引介增强,相当于IntroductionInterceptor

    3 execution切点函数

    execution函数用于匹配方法执行的连接点,语法为:

    execution(方法修饰符(可选)  返回类型  方法名  参数  异常模式(可选)) 

    参数部分允许使用通配符:

    *  匹配任意字符,但只能匹配一个元素

    .. 匹配任意字符,可以匹配任意多个元素,表示类时,必须和*联合使用

    +  必须跟在类名后面,如Horseman+,表示类本身和继承或扩展指定类的所有类

    示例中的* chop(..)解读为:

    方法修饰符  无

    返回类型      *匹配任意数量字符,表示返回类型不限

    方法名          chop表示匹配名称为chop的方法

    参数               (..)表示匹配任意数量和类型的输入参数

    异常模式       不限

    springaopxml配置意思

    <!--
     2 <bean id="transactionManager"
     3         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
     4         <property name="dataSource" ref="jamon-proxy-DataSource"></property>
     5     </bean>
     6 -->
     7 <!-- 事务通知 -->   
     8     <tx:advice id="txAdvice" transaction-manager="transactionManager">   
     9         <tx:attributes>   
    10             <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception,SmoException,BmoException,DaoException" />   
    11             <tx:method name="del*" propagation="REQUIRED" rollback-for="Exception,SmoException,BmoException,DaoException" />   
    12             <tx:method name="upd*" propagation="REQUIRED" rollback-for="Exception,SmoException,BmoException,DaoException" />
    13    <tx:method name="*" propagation="SUPPORTS" read-only="true" />
    14   </tx:attributes>
    15  </tx:advice>
    16  <!-- Spring AOP config 
    17  解释一下(* com.evan.crm.service.*.*(..))中几个通配符的含义:
    18  第一个 * —— 通配 任意返回值类型
    19  第二个 * —— 通配 包com.evan.crm.service下的任意class
    20  第三个 * —— 通配 包com.evan.crm.service下的任意class的任意方法
    21  第四个 .. —— 通配 方法可以有0个或多个参数
    22   -->
    23  <aop:config>
    24   <aop:pointcut id="servicesPointcut" expression="execution(* com.jstrd.mss..*SMOImpl.*(..))" />
    25   <aop:advisor advice-ref="bluePrint.txAdvice" pointcut-ref="servicesPointcut" />  
    26  </aop:config>   
    27  </beans>   
    View Code
  • 相关阅读:
    CF 1006C Three Parts of the Array【双指针/前缀和/后缀和/二分】
    经验笔记二
    CF 1006B Polycarp's Practice【贪心】
    CF 1003D Coins and Queries【位运算/硬币值都为2的幂/贪心】
    CF 1003C Intense Heat【前缀和/精度/双层暴力枚举】
    CF 1003B Binary String Constructing 【构造/找规律/分类讨论】
    CF 1005C Summarize to the Power of Two 【hash/STL-map】
    CF 1005B Delete from the Left 【模拟数组操作/正难则反】
    CF 1005A Tanya and Stairways 【STL】
    CF 1009A Game Shopping 【双指针/模拟】
  • 原文地址:https://www.cnblogs.com/shangxiaofei/p/9215008.html
Copyright © 2011-2022 走看看