2017-04-11 70 views
0

我正在使用Spring AOP截取由@MyAnnotation注解的方法。拦截是好的。但是,不幸的是,我没有得到我的注释实例。Spring AOP by annotation pointcut annotation not retrieve

我译注:

@Retention(RetentionPolicy.RUNTIME) 
@Target(ElementType.METHOD) 
public @interface MyAnnotation { 
    String[] description(); 
} 

我的配置看点

@Aspect 
public class OAuthAspect { 

    @Pointcut(value = "execution(public * *(..))") 
    public void anyPublicMethod() { 
    } 

    @Pointcut(value = "@annotation(annotation)", argNames = "annotation") 
    public void anyAnnotationMethod(MyAnnotation annotation) { 
    } 

    @Around(value = "anyPublicMethod() && anyAnnotationMethod(annotation)") 
    public Object authorization(ProceedingJoinPoint pjp, MyAnnotation annotation) throws Throwable { 
     //annotation is null 
    } 
} 

例切入点:

@Service 
public class ContextService { 
    @MyAnnotation(description = {"de1", "des2"}) 
    public String getAll() { 
    } 
} 

我不明白为什么我无法检索注释实例。

如果有人有想法?

PC:编辑

回答

0

对我来说,类ContextService甚至不编译,因为在你的注释里有打字错误:String[] descrition();(注意失踪“P”)确实应该String[] description();,然后再编译,我还可以打印注释实例。

+0

对于“描述”是合理的转录错误。在我的projet中,'p'存在并且我的projet编译,但注解实例是null:'( –

+0

然后你有一个配置问题。我在AspectJ上测试了我的机器上的方面,并且它工作。如果你不同意,请提供完整的[MCVE](http://stackoverflow.com/help/mcve),包括通过GitHub构建的Maven。 – kriegaex

+0

好吧,它可以工作,我已经很难清理了我的projet和它没关系,我认为我在构建projet时遇到了问题,谢谢你的帮助:) –