spring boot repository event handler

Spring boot is an awesome “wrapper” which allows Spring projects to be created and run with minimal configuration and it makes development fun again. While exploring Spring boot repositories, I needed to perform certain actions based on entities being created or deleted:

Defining a Spring Repository:

	public interface UserRepository extends CrudRepository<User, Long>
	{
	}

To capture events emitted when entities are created or destroyed:

@RepositoryEventHandler(User.class)
@RestController
public class UserEventHandler {


	@HandleAfterCreate(User.class)
	public void handleUserSave(User user) {
		/* to do */
	}
}

The above class will execute the method whenever a User object is created. Similar annotations for deletions and updates exist.