@Test public void springConditionalEventListener() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(DomaEventEntityListener.class); context.register(DomaEventListenerFactory.class); context.register(TodoListener.class); context.register(PreInsertHandler.class); context.refresh(); DomaEventEntityListener<Todo> entityListener = context .getBean(DomaEventEntityListener.class); TodoListener todoListener = context.getBean(TodoListener.class); PreInsertContext ctx = mock(PreInsertContext.class); Todo entity = new Todo(); entity.createdBy = "someone"; entityListener.preInsert(entity, ctx); Todo todo = todoListener.todo; assertThat(todo).isNull(); entity.createdBy = "making"; entityListener.preInsert(entity, ctx); todo = todoListener.todo; assertThat(todo).isNotNull(); assertThat(todo).isSameAs(entity); }
@Override public void preInsert(T t, PreInsertContext<T> context) { this.eventPublisher.publishEvent(new PreInsertEvent<>(t, context)); }
DomaEventEntityListener extends NullEntityListener<T> implements
		ApplicationEventPublisherAware { @Override public void preInsert(T t, PreInsertContext<T> context) { this.eventPublisher.publishEvent(new PreInsertEvent<>(t, context)); } }
DomaEventEntityListener extends NullEntityListener<T> implements
		ApplicationEventPublisherAware { @Override public void preInsert(T t, PreInsertContext<T> context) { this.eventPublisher.publishEvent(new PreInsertEvent<>(t, context)); }  }
DomaEventEntityListener extends NullEntityListener<T> implements
		ApplicationEventPublisherAware { @Override public void preInsert(T t, PreInsertContext<T> context) { this.eventPublisher.publishEvent(new PreInsertEvent<>(t, context)); }  @Override void preInsert(T t, PreInsertContext<T> context); @Override void preUpdate(T t, PreUpdateContext<T> context); @Override void preDelete(T t, PreDeleteContext<T> context); @Override void postInsert(T t, PostInsertContext<T> context); @Override void postUpdate(T t, PostUpdateContext<T> context); @Override void postDelete(T t, PostDeleteContext<T> context); @Override void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher); }
DomaEventEntityListener extends NullEntityListener<T> implements
		ApplicationEventPublisherAware { @Override public void preInsert(T t, PreInsertContext<T> context) { this.eventPublisher.publishEvent(new PreInsertEvent<>(t, context)); }  @Override void preInsert(T t, PreInsertContext<T> context); @Override void preUpdate(T t, PreUpdateContext<T> context); @Override void preDelete(T t, PreDeleteContext<T> context); @Override void postInsert(T t, PostInsertContext<T> context); @Override void postUpdate(T t, PostUpdateContext<T> context); @Override void postDelete(T t, PostDeleteContext<T> context); @Override void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher);  }