繁体   English   中英

不会触发针对第三方JAR类的切入点

[英]Pointcut targeting a third party JAR class is not triggered

作为该错误https://github.com/spring-projects/spring-hateoas/issues/220的临时修复,我想修改org.springframework.hateoas.core.AnnotationMappingDiscoverer.getMapping方法的返回值,以便我可以手动解析占位符。 这是我尝试过的方面:

<aop:aspectj-autoproxy />
@Component
@Aspect
public class AnnotationMappingDiscovererFix {

  @Around("execution(* org.springframework.hateoas.core.AnnotationMappingDiscoverer.getMapping(..))")
  public Object resolvePlaceholders(ProceedingJoinPoint joinPoint) throws Throwable {
    Object mapping = joinPoint.proceed();
    // resolve placeholders manually...
    return mapping;
  }

}

但是这个切入点永远不会触发,为什么?

使用基于代理的Spring AOP,您只能定位到Spring Bean /组件。 我不是Spring用户,所以我不确定,但由于“母鸡与鸡蛋”自举问题,我不认为您可以通过其自己的AOP框架实际拦截Spring框架类。

但是,如果您通过加载时编织(LTW)使用完整的AspectJ,则应该能够实现所需的功能,因为AspectJ编织代理( Aspectjweaver.jar )在Spring类之前加载,因此可以在类加载阶段对其进行修改。 Spring文档说明了如何结合使用AspectJ和Spring。

暂无
暂无

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

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