Raf*_*ael 2 java spring-data-jpa spring-boot
我正在尝试RepositoryEventListener在春季启动应用程序中工作,但我想我做错了什么...
这是侦听器中的代码
@SuppressWarnings("rawtypes")
public class BeforeSaveEventListener extends AbstractRepositoryEventListener {
@Override
public void onBeforeSave(Object customer) {
throw new RuntimeException("++++ BEFORE SAVE EVENT ++++");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的应用程序类
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(Application.class);
springApplication.addListeners(new BeforeSaveEventListener());
springApplication.run(args);
}
}
Run Code Online (Sandbox Code Playgroud)
在保存操作中,我可以看到触发了以下事件:
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!
Run Code Online (Sandbox Code Playgroud)
因此,没有看到“ BeforeSave”事件……也许是文档中不推荐使用的东西,或者spring-boot机制可能有所不同?
| 归档时间: |
|
| 查看次数: |
5628 次 |
| 最近记录: |