mad*_*nce 5 java spring-aop spring-data-jpa spring-boot
问题很简单
@Around("execution(* package.*Repository.save(..))")
public Object saveInterupt(ProceedingJoinPoint joinPoint) throws Throwable {
// This gets called whenever repository save is called
}
@Around("execution(* package.*Repository.findAll(..))")
public Object findInterupt(ProceedingJoinPoint joinPoint) throws Throwable {
// This IS NOT GETTING called whenever repository findAll is called
}
Run Code Online (Sandbox Code Playgroud)
在这里打破头!
编辑:一个小突破。我打印了 target ,它返回SimpleJpaRepository而不是实际存储库。
小智 -1
你使用 Spring-BOOT 吗?Spring-BOOT 中的方面仅在第一次调用类中的单个方法时调用建议。如果您希望 Spring-BOOT 在任何给定类中的多个方法的所有情况下都尊重您的 @Around 建议——您需要将该类作为 bean 访问(SB 的 @Bean)...
Spring-BOOT 的 AOP 与使用 AspectJ 的切面并不 100% 相同——主要区别是 AspectJ 修改了 Spring 使用动态代理的字节码。
| 归档时间: |
|
| 查看次数: |
342 次 |
| 最近记录: |