I have created a custom annotation for some logging purpose. This annotation is applied over spring jpa repository created in project by extending JpaRepository. So what is happening now is that for read methods it is working correctly but for save part @Around advice never get invoked. Below is my @Around advice
@Around("@within(com.myproject.annotations.RepoAware)")
public void log(final ProceedingJoinPoint jp){
return log(jp,true);
}
my log method is taking one boolean argument on the basis of which i log something.Below is the repo code
@Repository
@RepoAware
public interface MyRepo extends JpaRepository<Student,Long>{
}
Now when i call repo method that is not part of my repository MyRepo like save, saveAll or specifically the method that exists in parent hierarchy then @Around advice not working. When i applied debugger then i can see that during save call proxy is of type CrudRepository. So when i override the save method in MyRepo.class it starts working. I am confused here because MyRepo eventually has CrudRepository extended through JpaRepository. Please let me know how to fix this or what i am doing wrong here.
Also provide help over how to use not expression in pointcut. Say for above example i want to target my all repositories except that have @RepoAware annotation. I created below advice but it's also not working.
@Around("target(org.springframework.data.jpa.repository.JpaRepository) and !@within(com.myproject.annotations.RepoAware)")
public Object logDBMetrics(final ProceedingJoinPoint pjp) throws Throwable {
return log(pjp,false);
}
above advice get invoked also for repos that have @RepoAware annotation.
Thanks in advance !