I am trying to add a RepositoryEventHandler as described on Spring Data REST documentation to the REST repository shown below:
@RepositoryRestResource(collectionResourceRel = "agents", path = "/agents")
public interface AgentRepository extends CrudRepository<Agent, Long> {
// no implementation required; Spring Data will create a concrete Repository
}
I created an AgentEventHandler:
@Component
@RepositoryEventHandler(Agent.class)
public class AgentEventHandler {
/**
* Called before {@link Agent} is persisted
*
* @param agent
*/
@HandleBeforeSave
public void handleBeforeSave(Agent agent) {
System.out.println("Saving Agent " + agent.toString());
}
}
and declared it in a @Configuration component:
@Configuration
public class RepositoryConfiguration {
/**
* Declare an instance of the {@link AgentEventHandler}
*
* @return
*/
@Bean
AgentEventHandler agentEvenHandler() {
return new AgentEventHandler();
}
}
When I am POSTing to the REST resource, the Entity gets persisted but the method handleBeforeSave never gets invoked. What am I missing?
I'm using: Spring Boot 1.1.5.RELEASE
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…