java - Save方法被拦截但findAll没有被拦截

标签 java spring-boot spring-data-jpa spring-aop

问题很简单

@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/

相关文章:

java - 如何在java应用程序中打开文件夹windows?我想在我的应用程序中插入文件 .txt 的路径

java - Spring @RestController 是否默认启用 CORS?

maven - 如何在 Spring Boot Maven 多模块项目中包含来自另一个模块的资源

java - 无法解析 Mockito 单元测试中的占位符

java - 在 Spring 规范中渴望获取

java - 为什么当我覆盖 hashcode 并从 hashmap 获取值时需要覆盖 equals

java - java中的字节数组

java - Jzy3d API 的正确 jar 文件是什么?

java - 数据库变更和 Spring Boot JPA

java - Hibernate StackOverflowError 与 @OneToMany 和 @ManyToOne 映射