0
@Component
@RepositoryEventHandler({Person.class})
public class RepositoryListener  {
@HandleBeforeDelete
public void handleEventBeforeDelete(Person person){
    java.lang.System.out.println("handleAuthorBeforeCreate");
}
@HandleAfterDelete
public void handleEventAfterDelete(Person person){
    java.lang.System.out.println("handleAuthorAfterCreate");
}
@HandleBeforeSave
public void handleEventBeforeSave(Event event){
    java.lang.System.out.println("handleAuthorBeforeSave");
}
@HandleAfterSave
public void handleEventAfterSave(Perrson person){
    java.lang.System.out.println("yulin-11 handleAuthorAfterSave");
}
@HandleBeforeCreate
public void handEventBeforeCreate(Person person){
    java.lang.System.out.println("handEventBeforeCreate");
}
@HandleAfterCreate
public void handleEventAfterCreate(Person person){
    java.lang.System.out.println("handleEventAfterCreate");
}
}

I create the RepositoryListener as above. When I fire delete and post rest call in the controller, it doesn't invoke any of those methods in the RepositoryListener. (Person is my domain class). Does anyone know what I am missing? thx!

lin
  • 167
  • 1
  • 3
  • 13
  • Q: What is your "repository"? For example, an Oracle 11g RDBMS? Q: How are you "firing a delete"? A stored procedure in a database? Q: What version of Spring Boot are you using? How are you running your app? In Eclipse? Tomcat? On a production server? – paulsm4 Nov 29 '18 at 00:04
  • I am using intellij maven. this is my Person Repository class: public interface PersonRepository extends JpaRepository {}. I am using springboot 2.0.5.release. – lin Nov 29 '18 at 00:12
  • Q: So how do you "fire a delete"? What sequence of actions/events cause a "delete" to "fire"? Does a user click something on a web page? Is the database involved prior to Spring Boot getting called? What exactly leads up to this "event" your controller doesn't seem to be getting? – paulsm4 Nov 29 '18 at 01:00
  • it is an REST. I am using postman localhost:8080/person/id, choose delete option to fire the controller. – lin Nov 29 '18 at 01:03
  • Got it. So the problem has nothing to do with the database: you're using Postman to invoke your Spring Boot API. SUGGESTIONS: 1) [Enable verbose trace logging](https://www.baeldung.com/spring-http-logging), 2) [Use your IntelliJ debugger](https://www.javadevjournal.com/spring/remote-debug-spring-boot-application-with-maven-and-intellij/) – paulsm4 Nov 29 '18 at 01:07
  • the problem is the RepositoryListener class has never been called. – lin Nov 29 '18 at 01:13
  • have you tried to use `@RepositoryEventHandler(Person.class)`? Also, you don't have to declare your class as a `@Component` – Vitalii Strimbanu Nov 29 '18 at 02:16
  • We get that "the RepositoryListener class has never been called". Now we need to figure out WHY. One way is to "guess", and "try stuff". A *BETTER* way is to try to get more information to analyze the problem. Trace logging is one tool that could help; a good debugger is another tool Please consider trying them. – paulsm4 Nov 29 '18 at 05:33

1 Answers1

0

Check that comment below most probably it the answer, I didn't try it myself

It is called on the HTTP Requests done to the Data-REST exposed repositories, but not when you use any repository-method programmatically

link mentioned here

Mostafa Hassan
  • 288
  • 1
  • 14