zoukankan      html  css  js  c++  java
  • spring in action 学习笔记二:aop的理解

      一: aop的思想的来在哪里?

    一个系统一般情况下由多个组件组成,而每一个组件除了干自己的本职工作以外,有时还会干一些杂活(如:日志(logging)、事务管理(transaction manager)、安全(secure)),而恰好这些杂活其他组件也要干,那么这时一个人想了想能不能只让每个组件干好自己的本职工作,这些杂活由专门的人负责,这样的工作效率肯定会大大提高。

    这专门负责杂活的人就是切面(Aspect).这就是aop思想的来源。

       二:aop的核心代码:

     1  <bean id="minstrel" class="com.qls.impl.Minstrel">
     2         <constructor-arg value="#{T(System).out}"/>
     3     </bean>
     4     <aop:config>
     5         <aop:aspect ref="minstrel">
     6             <aop:pointcut id="embark" expression="execution(* *.embarkOnQuest(..))"/>
     7             <aop:before method="singBeforeQuest" pointcut-ref="embark"/>
     8             <aop:after method="singAfterQuest" pointcut-ref="embark"/>
     9         </aop:aspect>
    10     </aop:config>

    这里要说明一下要想让spring的aop正常运转起来:需要加上aopalliance.jar      aspectj.jar   aspectweaver.jar这三个jar包。

  • 相关阅读:
    Type Safety and Type Inference
    LEARN SWIFT
    swift 类型备份
    Swift
    associatedtype关联类型
    深入理解 Swift 派发机制
    Swift中self和Self
    Postfix Self Expression
    CGContext与上下文
    eeee
  • 原文地址:https://www.cnblogs.com/1540340840qls/p/6947736.html
Copyright © 2011-2022 走看看