簡體   English   中英

使用Spring和AspectJ攔截私有方法

[英]Intercept private methods with Spring and AspectJ

我試圖在使用私有方法使用AspectJ的Spring-Boot加載時編織和基於注釋的配置之前執行代碼,並且試圖弄清楚為什么未調用我的方面,這使我望而卻步。

我的簡單方面如下:

@Aspect
public class LoggingAspect {

  private static Logger log = LoggerFactory.getLogger(LoggingAspect.class);

  @Before("execution(private * com.mycompany.MyServiceWithPrivateMethods.*(..))")
  public void privateAspect() {
    log.warn("#### Private method aspect invoked!");
  }

}

我在Spring配置類上還有@EnableLoadTimeWeaving批注,在META-INF / aop.xml中也有@EnableLoadTimeWeaving批注:

<aspectj>    
    <weaver options="-verbose">
        <!-- only weave classes in our application-specific packages -->
        <include within="com.mycompany.*"/>
    </weaver>

    <aspects>
        <!-- weave in just this aspect -->
        <aspect name="com.mycompany.LoggingAspect"/>
    </aspects>    
</aspectj>

最后,根據文檔,我還使用-javaagent:/path/to/spring-instrument.jar選項啟動應用程序。 我在類路徑上也有必需的jars( spring-aopaspectjweaver ),如Spring文檔中所述。

這有可能嗎? AspectJ文檔中列出了一個“限制”,指出Privileged aspects are not supported by the annotation style. 位於此處 ,但是春季論壇上的這篇較舊的帖子似乎表明確實有可能。

我本來以為它會起作用,但是我也以為您必須將Aspectjweaver.jar添加為javaagent。 這些假設之一是錯誤的?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM