[英]Listening repository events in spring-boot
I am trying RepositoryEventListener to work in spring-boot application but i guess im doing something wrong ... 我正在尝试RepositoryEventListener在春季启动应用程序中工作,但我想我做错了什么...
This is the code in the Listener 这是侦听器中的代码
@SuppressWarnings("rawtypes")
public class BeforeSaveEventListener extends AbstractRepositoryEventListener {
@Override
public void onBeforeSave(Object customer) {
throw new RuntimeException("++++ BEFORE SAVE EVENT ++++");
}
}
This is my Application class 这是我的应用程序类
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(Application.class);
springApplication.addListeners(new BeforeSaveEventListener());
springApplication.run(args);
}
}
On save operation i can see these events fired: 在保存操作中,我可以看到触发了以下事件:
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!
So no "BeforeSave" event seen ... maybe is something deprecated on documentation, or spring-boot mechanisms may be different? 因此,没有看到“ BeforeSave”事件……也许是文档中不推荐使用的东西,或者spring-boot机制可能有所不同?
As explained here Spring-Data-Rest Validator 如此处所述, Spring-Data-Rest验证程序
" ... it appears that the before/after "save" events only fire on PUT and PATCH. When POSTing, the before/after "create" events fire." “……看来,“保存”之前/之后的事件仅在PUT和PATCH上触发。发布时,“创建”之前/之后的事件才触发。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.