使用Aspectj加载时间编织来记录我的源代码(包括测试),而无需记录外部库

问题描述 投票:0回答:1

我仅在执行测试时才使用AspectJ进行日志记录,因此我使用加载时间编织。我将Interceptor打包到一个jar文件中,以便与另一个Maven项目一起使用。但是使用下面的配置,Aspectjweaver将编织外部库的方法。我希望它只编织我的源代码(包括测试)而没有像<include within="hello.*"/>这样的特定配置,以便使用类似的依赖项进行通用。

[抱歉,我的英语不好。非常感谢!!!

在此jar文件的aop.xml中,它喜欢

<aspectj>
<aspects>
    <aspect name="log.Interceptor"/>
    <weaver options="-verbose -showWeaveInfo">
        <include within="*"/>
    </weaver>
</aspects>
</aspectj>

//拦截器

pointcut traceMethods() : (execution(* *(..)) && !cflow(within(Interceptor)) && !within(*Test) && !within(Test*) && !within(*Tests) && !within(*TestCase));
before(): traceMethods(){
    Method method = ((MethodSignature) thisJoinPointStaticPart.getSignature()).getMethod();
    logDebug(method, LogPattern.METHOD_START);
}
after(): traceMethods(){
    Method method = ((MethodSignature) thisJoinPointStaticPart.getSignature()).getMethod();
    logDebug(method, LogPattern.METHOD_FINISH);
}` 

我仅在执行测试时才使用AspectJ进行日志记录,因此我使用加载时间编织。我将Interceptor打包到一个jar文件中,以便与另一个Maven项目一起使用。但是使用下面的配置,aspectjweaver将...

java logging aspectj load-time-weaving
1个回答
0
投票

嗯,你不能同时吃蛋糕和保留蛋糕。因此,您的解决方案要么是针对整个世界的通用切入点,要么是通过包含和/或排除而特定的。

© www.soinside.com 2019 - 2024. All rights reserved.