2011-03-12 73 views
10

考虑我已经定义了以下方面的参数:Spring AOP的:获取切入点注解

@Aspect 
public class SampleAspect { 

    @Around(value="@annotation(sample.SampleAnnotation)") 
    public Object display(ProceedingJoinPoint joinPoint) throws Throwable { 
     // ... 
    } 
} 

和注释

public @interface SampleAnnotation { 
    String value() default "defaultValue"; 
} 

有没有办法读取注释SampleAnnotation参数的值在显示方法,如果我的方面?

感谢您的帮助, 埃里克

+1

[访问注解值的建议](http://stackoverflow.com/questions/5026247/accessing-annotation-value-in-advice) – axtavt 2011-03-12 11:45:37

回答

10

更改建议的签名

@Around(value="@annotation(sampleAnnotation)") 
public Object display(ProceedingJoinPoint joinPoint, SampleAnnotation sampleAnnotation) throws Throwable { 
    // ... 
} 

,你将有机会获得在注释的值。

有关更多信息,请参阅docs

+1

可能的重复深入文档检查:http:// docs .spring.io/spring/docs/3.0.3.RELEASE/spring-framework-reference/html/aop.html - 7.2.4.6节建议参数 – hoodieman 2015-04-21 11:15:52