我目前正在开发一个多模块gradle项目,其中所有模块都依赖于foo-common
模块。 Foo-common是唯一没有主要功能的人。我想将AOP与AspectJ集成,为了做到这一点,我遵循了Official IntelliJ Documentation中的以下步骤:
aspectjrt.jar
创建了一个库,并使用this documentation将其作为依赖项添加到foo-common_main
和foo-bar_main
模块。javac
更改为ajc
。Build | AspectJ Weaving
foo-common
的{{1}}和foo-bar
的项目结构中创建了AspectJ Facets 我的文件如下所示:
Aspect.java(Post-compile weave mode
模块)
foo-common
ApplicationConfiguration.java(@Aspect
public class TraceAspect extends Pointcuts {
private static final Logger logger = LoggerFactory.getLogger(TraceAspect.class);
@Before("call(* com.package.foo..*(..))")
public void calling(JoinPoint joinPoint) {
logger.trace("[CALL] " + joinPoint.getSignature().toString());
}
@Before("execution(* com.package.foo..*(..))")
public void initiating(JoinPoint joinPoint) {
logger.trace("[EXEC] " + joinPoint.getSignature().toString());
}
}
模块)
foo-bar
项目本身编译并运行。如果我尝试修改@SpringBootConfiguration
public class ApplicationConfiguration{
private static final Logger logger = LogManager.getLogger(ApplicationConfiguration.class);
@Bean
public DummyClientFactory dummyClientFactory() {
return new dummyClientFactoryImpl();
}
}
以获得手动日志语句,那也可以。我可以看到IntelliJ使用智能来指出哪些建议连接到哪些方法。但是我无法通过Aspects看到生成的日志。