简体   繁体   English

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

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

As a temporary fix of the bug https://github.com/spring-projects/spring-hateoas/issues/220 , I would like modify the return value of org.springframework.hateoas.core.AnnotationMappingDiscoverer.getMapping methods so that I can resolve placeholders manually. 作为该错误https://github.com/spring-projects/spring-hateoas/issues/220的临时修复,我想修改org.springframework.hateoas.core.AnnotationMappingDiscoverer.getMapping方法的返回值,以便我可以手动解析占位符。 Here is the aspect I tried: 这是我尝试过的方面:

<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;
  }

}

But this pointcut gets never triggered, any idea why? 但是这个切入点永远不会触发,为什么?

With proxy-based Spring AOP you can only target Spring beans/components. 使用基于代理的Spring AOP,您只能定位到Spring Bean /组件。 I am not a Spring user, so I do not know for sure, but I do not think that you can actually intercept Spring framework classes via its own AOP framework due to "hen vs. egg" bootstrapping problems. 我不是Spring用户,所以我不确定,但由于“母鸡与鸡蛋”自举问题,我不认为您可以通过其自己的AOP框架实际拦截Spring框架类。

But if you use full AspectJ via load-time weaving (LTW), you should be able to achieve what you want because the AspectJ weaving agent ( aspectjweaver.jar ) is loaded before the Spring classes and thus can modify them during classloading phase. 但是,如果您通过加载时编织(LTW)使用完整的AspectJ,则应该能够实现所需的功能,因为AspectJ编织代理( Aspectjweaver.jar )在Spring类之前加载,因此可以在类加载阶段对其进行修改。 The Spring documentation explains how to use AspectJ in connection with Spring. Spring文档说明了如何结合使用AspectJ和Spring。

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

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