我的问题很简单。为什么这种形式有效:
@Bean
public ApplicationListener<BeforeSaveEvent> beforeSaveEventApplicationListener() {
return new ApplicationListener<BeforeSaveEvent>() {
@Override
public void onApplicationEvent(BeforeSaveEvent beforeSaveEvent) {
Object eventEntity = beforeSaveEvent.getEntity();
if (eventEntity instanceof Node) {
Node node = (Node) eventEntity;
node.initUniqueProperties();
}
}
};
}
这不起作用:
@Bean
public ApplicationListener<BeforeSaveEvent> beforeSaveEventApplicationListener() {
return beforeSaveEvent -> {
Object eventEntity = beforeSaveEvent.getEntity();
if (eventEntity instanceof Node) {
Node node = (Node) eventEntity;
node.initUniqueProperties();
}
};
}
我想,他们是等同的。但我在第二种情况下收到一个例外:
org.springframework.context.event.ContextRefreshedEvent不能 施放到org.springframework.data.neo4j.event.BeforeSaveEvent。
为什么?