V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
esolve
V2EX  ›  Java

Spring AOP 中 @within 和 @annotation 有啥区别?

  •  
  •   esolve · May 8, 2017 · 5050 views
    This topic created in 3286 days ago, the information mentioned may be changed or developed.

    例如 @within(org.springframework.transaction.annotation.Transactional) 和 @annotation(org.springframework.transaction.annotation.Transactional)

    感觉是一个意思?

    6 replies    2017-05-08 19:19:33 +08:00
    springmarker
        1
    springmarker  
       May 8, 2017
    within(com.common.xxx*) && @annotation(hello)
    指定 com.common.xxx 目录下及其所有子目录下的所有带有 @hello 注解的方法体为切点。
    esolve
        2
    esolve  
    OP
       May 8, 2017
    @springmarker

    这里说的是 @within
    不是 within
    justicelove
        3
    justicelove  
       May 8, 2017
    spring aop 使用的是 aspectj 的注解,可以百度下 aspectj
    springmarker
        4
    springmarker  
       May 8, 2017
    哦抱歉,看错了,文档的意思是 一个是对象级别的,一个是方法级别的。
    注解写在方法上,@within 的是不会执行的,@annotation 的会执行,反之亦然
    esolve
        5
    esolve  
    OP
       May 8, 2017
    @springmarker

    以下面连个为例

    @within(org.springframework.transaction.annotation.Transactional) 和 @annotation(org.springframework.transaction.annotation.Transactional)

    如果是 @annotation 的话,意思是对方法实施事务
    但是如果是 @within 的话,是啥意思?
    springmarker
        6
    springmarker  
       May 8, 2017
    你写个例子不就好了,分别在方法和类上加注解,再看用 @within 和 @annotation 有什么区别,几分钟的事情,比我在这跟跟你讲理解的快得多。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6003 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 03:19 · PVG 11:19 · LAX 20:19 · JFK 23:19
    ♥ Do have faith in what you're doing.