How can I add a specific code in the implementations of methods that are listed in jparepository of spring data jpa without creating a new method in an interface that extending jparepository. I want to edit the body of some methods listed in jparepository. for example in save method body: add[system.out.println("before persisting");] just before calling persist method and [system.out.println("after persisting");] just after a persist calling Thanks
Asked
Active
Viewed 136 times
1 Answers
0
You can introduce some aspect. It will provide you implement whatever you want. You can see similar example here Spring AOP + JPARepository Something similar to this
@Aspect
@Component
@Configurable
public class AuditLogAspect {
@Pointcut("execution(* org.springframework.data.repository.CrudRepository+.save(*))")
public void whenSaveOrUpdate() {};
@Before("whenSaveOrUpdate() && args(entity)")
public void beforeSaveOrUpdate(JoinPoint joinPoint, BaseEntity entity) {...}
}

cool
- 1,746
- 1
- 14
- 15