Java 在spring boot中侦听存储库事件

Java 在spring boot中侦听存储库事件,java,spring-boot,spring-data-jpa,Java,Spring Boot,Spring Data Jpa,我正在尝试RepositoryEventListener在spring启动应用程序中工作,但我猜我做错了什么 这是侦听器中的代码 @SuppressWarnings("rawtypes") public class BeforeSaveEventListener extends AbstractRepositoryEventListener { @Override public void onBeforeSave(Object customer) { thr

我正在尝试RepositoryEventListener在spring启动应用程序中工作,但我猜我做错了什么

这是侦听器中的代码

@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引导机制可能不同?

如本文所述

“…似乎“保存”之前/之后的事件仅在放置和修补时触发。发布时,“创建”之前/之后的事件触发。”