美文网首页
chapter04_面向切面的Spring_2_切点

chapter04_面向切面的Spring_2_切点

作者: 米都都 | 来源:发表于2019-01-14 09:31 被阅读0次
    • Spring AOP 中,使用AspectJ的切点表达式语言来定义切点,但是只使用一部分,因为Spring不支持字段级别的切面,而AspectJ支持

    • 常用切点指示器

      execution()

      arg()

      within()

    • 编写切点

      (1) 示例

        execution(* concert.Performance.perform(..))
      

      (2) 说明

      第一个*代表返回任意类型

      中间的 concert.Performance代表方法所属的类

      perform()代表要插入切面的方法

      ..代表使用任意参数

      (3) 可以使用多个切点指示器,例如

        execution(* concert.Performance.perform(..)) and bean('woodstock')
      

      代表限定id为woodstock的bean才会插入切面

      (4) 使用 Java Config,连接使用 &&, ||, !

      (5) 使用 xml,连接使用 and, or, not

    相关文章

      网友评论

          本文标题:chapter04_面向切面的Spring_2_切点

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