chapter04_面向切面的Spring_2_切点

  • 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

猜你喜欢

转载自blog.csdn.net/captxb/article/details/87872513