我有同样的问题。在我的情况下,我不得不使用注释@Component注释我的方面类。
@Aspect @Component public class MyAspect { ... }
以下链接有一个帮助我的弹簧启动AOP示例
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-aop
在代码中添加以下更改,它应该可以正常工作。不需要创建aop.xml。这些更改会将方面添加到容器中并编织它。
阅读 - 启用Spring AOP或AspectJ
@Configuration @ComponentScan @EnableJpaRepositories @EnableTransactionManagement @EnableAutoConfiguration @EnableCaching @EnableAspectJAutoProxy -- Use this instead of @EnableLoadTimeWeaving public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } @Aspect @Component/@Configurable -- Both of them work public class MyAspect { ... }
为了建议私人方法,你需要使用 的 特权 强> 方面:
public privileged aspect MyAspect { // ... }
但是 AspectJ文档 说:
的 限制: 强> 注释样式不支持特权方面。
所以请使用原生语法,而不是@AspectJ样式。但是,在您执行此操作之前,请测试非特权,注释样式方面是否按预期使用公共方法工作,以排除编辑方面的其他原因。