I'm using Neo4j OGM 2.1.3
with Spring Boot 1.5.9
in the documentation reference of both spring data and neo4j ogm, registration of event listener is explained as the following code.
class AddUuidPreSaveEventListener implements EventListener {
void onPreSave(Event event) {
DomainEntity entity = (DomainEntity) event.getObject():
if (entity.getId() == null) {
entity.setUUID(UUID.randomUUID());
}
}
void onPostSave(Event event) {
}
void onPreDelete(Event event) {
}
void onPostDelete(Event event) {
}
EventListener eventListener = new AddUuidPreSaveEventListener();
// register it on an individual session
session.register(eventListener);
// remove it.
session.dispose(eventListener);
// register it across multiple sessions
sessionFactory.register(eventListener);
// remove it.
sessionFactory.deregister(eventListener);
In my code I can't find a way to get an instance of the session.
@SpringBootApplication
@EntityScan("movies.spring.data.neo4j.domain")
public class SampleMovieApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(SampleMovieApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
private static Class<SampleMovieApplication> applicationClass = SampleMovieApplication.class;
}
I run the project using the code snippet above.
My question is: how can I get an instance of the session and use it to register the event listener?.
Edit: my code is built using this code example on GitHub