V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
esolve
V2EX  ›  Java

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

  •  
  •   esolve · 2017-05-08 16:18:01 +08:00 · 4345 次点击
    这是一个创建于 2516 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    感觉是一个意思?

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

    这里说的是 @within
    不是 within
    justicelove
        3
    justicelove  
       2017-05-08 18:07:22 +08:00
    spring aop 使用的是 aspectj 的注解,可以百度下 aspectj
    springmarker
        4
    springmarker  
       2017-05-08 18:11:27 +08:00
    哦抱歉,看错了,文档的意思是 一个是对象级别的,一个是方法级别的。
    注解写在方法上,@within 的是不会执行的,@annotation 的会执行,反之亦然
    esolve
        5
    esolve  
    OP
       2017-05-08 19:05:28 +08:00
    @springmarker

    以下面连个为例

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

    如果是 @annotation 的话,意思是对方法实施事务
    但是如果是 @within 的话,是啥意思?
    springmarker
        6
    springmarker  
       2017-05-08 19:19:33 +08:00
    你写个例子不就好了,分别在方法和类上加注解,再看用 @within 和 @annotation 有什么区别,几分钟的事情,比我在这跟跟你讲理解的快得多。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2746 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 00:23 · PVG 08:23 · LAX 17:23 · JFK 20:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.