I'm using Spring Data in my project. So, I need to intercept some methods (save and delete) only from some entities only. I tried to configure the pointcut for my own repositories interfaces, but without success. The methods wasn't intercepted.
So, I found a solution that was to try to use the Spring CrudRepository interfaces into my pointcup.
@Aspect
@Component
@Configurable
public class AuditLogAspect {
@Pointcut("execution(* org.springframework.data.repository.CrudRepository+.save(*)) || " +
"execution(* org.springframework.data.repository.CrudRepository+.saveAndFlush(*))")
public void whenSaveOrUpdate() {};
@Pointcut("execution(* org.springframework.data.repository.CrudRepository+.delete(*))")
public void whenDelete() {};
@Before("whenSaveOrUpdate() && args(entity)")
public void beforeSaveOrUpdate(JoinPoint joinPoint, BaseEntity entity) {...}
}
That was a good aproach! The interceptor was executed sucessfully! But my scenario is a little bit different. I have about 20 interfaces that extends JPARepository inteface from Spring Data, then i need to intercep 15 of them. The other ones, I can't.
Thus, my question is: Is there a way to intercept some methods of my own interfaces that extends JPARepository interface from Spring Data, using AOP or anything else?
Thank's in advance for any help!