简体   繁体   English

Spring AOP:不使用自定义注释的方法执行建议

[英]Spring AOP: Advice not executing for method with custom annotation

I have created a custom annotation: 我创建了一个自定义注释:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ValidateBeforeBuild {
}

And an aspect as: 一个方面是:

@Aspect
@Component
public class AspectForBuildInBuilders {

    private static final Logger LOGGER = LoggerFactory.getLogger(AspectForBuildInBuilders.class);

    @Before("@annotation(validateBeforeBuild )")
    public void validateBusinessModelAdvice(JoinPoint jp, ValidateBeforeBuild validateBeforeBuild ) throws Throwable {
        LOGGER.info("Executing class: {}", jp);
    }
}

I have a build() that is marked with above annotation. 我有一个标有上面注释的build() When I am trying to call the build() , I am not getting the log message from the validateBusinessModelAdvice() . 当我尝试调用build() ,我没有从validateBusinessModelAdvice()获取日志消息。 I also have @EnableAspectJAutoProxy in one of the configuration classes. 我在其中一个配置类中也有@EnableAspectJAutoProxy Am I missing something? 我错过了什么吗? Is there any more information required? 是否还需要更多信息?

You defined your annotation as ValidateBeforeBuild and in your aspect you specified validateBeforeBuild (notice the upper V in your annotation) 您将注释定义为ValidateBeforeBuild并在您指定的validateBeforeBuild方面(注意注释中的上部V

Try changing 尝试改变

@Before("@annotation(validateBeforeBuild)")

for 对于

@Before("@annotation(ValidateBeforeBuild)")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM