I'm trying to capture the BeforeSaveEvent when setting up Neo4J in Spring, so that I can call a method beforeSave()
on the class that is being saved. Unfortunately, it seems like its not being registered as a listener as non of my print statements are being executed.
Ideas appreciated.
@Configuration
@EnableNeo4jRepositories(basePackages = "com.noxgroup.nitro")
@EnableTransactionManagement
public class NitroNeo4jConfiguration extends Neo4jConfiguration {
@Bean
public Neo4jServer neo4jServer () {
System.setProperty("username", "neo4j");
System.setProperty("password", "*************");
return new RemoteServer("http://localhost:7474");
}
@Bean
public SessionFactory getSessionFactory() {
return new SessionFactory("com.noxgroup.nitro.domain");
}
@Bean
ApplicationListener<BeforeSaveEvent> beforeSaveEventApplicationListener() {
return new ApplicationListener<BeforeSaveEvent>() {
@Override
public void onApplicationEvent(BeforeSaveEvent event) {
System.out.println("Listening to event");
Object entity = event.getEntity();
if (entity instanceof NitroNode) {
((NitroNode)entity).beforeSave();
} else {
System.out.println("Not picking it up");
}
}
};
}
}