I’ve made an application with Spring Roo (I’m still a newbie) and I’d like to do some processing after the entity is persisted. I’ve set up the application with Service and DAO layer. In the service I created a custom method called triggerChange(MyEntity myEntity). I’d like that this method would be invoked after saving the entity but I don’t know how could I call that method without modifying the *ServiceImpl_Roo_Service managed by Roo (which shouldn’t be editted).
So I have a code like this one:
The service:
public class MyEntityServiceImpl implements MyEntityService {
//this is the method I want to invoke inside or after invoking save()
public void triggerChange(MyEntity myEntity) {
...
}
}
The Aspect for the service:
privileged aspect MyEntityServiceImpl_Roo_Service {
...
public void MyEntityServiceImpl.saveMyEntity(MyEntity myEntity) {
myEntityRepository.save(myEntity);
}
}
How could I customize save method?
Thanks
You have AspectJ enabled in your Spring application thanks to Roo. Just create an Aspect (after or around the method call)
You also can to move the methods from the Roo aspects (.aj)