Spring AOP Pointcut does not trigger

回眸只為那壹抹淺笑 提交于 2019-12-02 11:55:36
Dmitry Kuskov

You have several problems with your code:

  1. You should create your ValidationTest object as a bean managed by Spring and not using new
  2. <aop:include name="UpdateUIMetadataInterceptor" /> should be <aop:include name="updateUI"/>; you can actually just stick with <aop:aspectj-autoproxy/> for simplicity here
  3. ProceedingJoinPoint is not supported for before aspects, so remove it; you can use JoinPoint instead if you need access to arguments
  4. JsonSchemaAnnotation jsonSchemaAnnotation parameter should be present for validateJson method of your aspect, as pointed out by frant.hartm

I think you need either fully qualified name or a parameter in the method:

FQN:

@Before("anyPublicMethod() && @annotation(your.package.JsonSchemaAnnotation)")
public void validateJson(ProceedingJoinPoint pjp) throws Throwable {
    System.out.println("Running");  
}

Parameter:

@Before("anyPublicMethod() && @annotation(jsonSchemaAnnotation)")
public void validateJson(ProceedingJoinPoint pjp, JsonSchemaAnnotation jsonSchemaAnnotation ) throws Throwable {
    System.out.println("Running");  
}

Source: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-pointcuts

(and you also need to use the bean, as Dmitry Kuskov pointed out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!