I have tried to configure spring data rest event as per follows.All classes are in package org.springbootjpa
Events: http://docs.spring.io/spring-data/rest/docs/current/reference/html/#events
Following is my code
@SpringBootApplication public class DemoApplication { public static void main(String[] args) { ApplicationContext context = SpringApplication.run( DemoApplication.class, args); String[] beanNames = context.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } } @Bean GroupEventHandler groupEventHandler() { return new GroupEventHandler(); } } Event Handler
@RepositoryEventHandler(UserGroup.class) public class GroupEventHandler { @HandleBeforeSave public void handleGroupSave(UserGroup group) { System.out.println("Inside handleGroupSave ...."); } @HandleAfterSave public void handleAfterSave(UserGroup group) { System.out.println("Inside handleAfterSave ...."); } } Entity
@Entity public class UserGroup { @Id @GeneratedValue private Long groupId; @Column private String groupName; .. } When I post an entry to the userGroups link the listener is not getting triggered.
post --data "{groupId:1,groupName:'group1'}"
DemoApplicationis in and the package of theDemoConfig. Suggesting instead of usingDemoConfigsimply add the@Beanmethod to theDemoApplication.@HandleBeforeCreateis called instead of save, which is for updates i..e PUT.