问题很简单
@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
}
这里让人头疼!
编辑:一个小小的突破。我打印了目标,它返回 SimpleJpaRepository
而不是实际存储库。
最佳答案
假设存储库具有以下结构
public interface JpaEmployeeRepository extends CrudRepository<JpaEmployee, Long> {..}
以下切入点适用于这两种情况
@Around("execution(* org..*Repository.save(..))")
和
@Around("execution(* org..*Repository.findAll(..))")
如果我正确理解了这个问题,则要求是拦截特定包中特定方法的执行。如果是,可以在此处阅读有关相同内容的更多详细信息。 @AspectJ pointcut for all methods inside package
关于java - Save方法被拦截但findAll没有被拦截,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59180446/