【发布时间】:2015-06-02 12:02:31
【问题描述】:
我正在尝试 RepositoryEventListener 在 spring-boot 应用程序中工作,但我想我做错了什么......
这是监听器中的代码
@SuppressWarnings("rawtypes")
public class BeforeSaveEventListener extends AbstractRepositoryEventListener {
@Override
public void onBeforeSave(Object customer) {
throw new RuntimeException("++++ BEFORE SAVE EVENT ++++");
}
}
这是我的应用程序类
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(Application.class);
springApplication.addListeners(new BeforeSaveEventListener());
springApplication.run(args);
}
}
在保存操作时,我可以看到这些事件被触发:
Current Event is org.springframework.data.rest.core.event.BeforeCreateEvent received!
Current Event is org.springframework.data.rest.core.event.AfterCreateEvent received!
Current Event is org.springframework.web.context.support.ServletRequestHandledEvent received!
所以没有看到“BeforeSave”事件...也许文档中已弃用某些内容,或者 spring-boot 机制可能不同?
【问题讨论】:
标签: java spring-boot spring-data-jpa