Spring 数据 Neo4j SDN 4 审计支持
Spring Data Neo4j SDN 4 Auditing Support
我正在尝试使用 Spring 数据和来自 spring-data-commons 的注释设置简单的实体审计字段(例如 @CreatedDate
类型 Long
作为这里提到 http://docs.spring.io/spring-data/commons/docs/current/reference/html/#auditing.annotations)
此处讨论了 Neo4j 2.0 的解决方案:Audits with Spring Data Neo4j。但是对于版本 4,class 似乎已经在发行版中消失了。
我假设必须将事件侦听器添加到 Neo4j 才能填充这些字段。但是我在 spring-data-neo4j 发行版的任何地方都找不到 @EnableMongoAuditing
(MongoDB) 和 @EnableJpaAuditing
(JPA) 的 neo4j 副本。
这是否意味着我必须忽略 Neo4j 上这个特定的 Spring 数据功能?还有其他选择吗?
@Polyakoff SDN 4 当前不支持公共库中的注释。为了解决这个问题,我必须创建一个 Spring bean 来监听保存前的事件,如下所示:
@Bean
ApplicationListener<BeforeSaveEvent> beforeSaveEventApplicationListener() {
return new ApplicationListener<BeforeSaveEvent>() {
@Override
public void onApplicationEvent(BeforeSaveEvent event) {
event.getEntity().setCreatedDate(System.currentTimeMillis());
}
};
}
我正在尝试使用 Spring 数据和来自 spring-data-commons 的注释设置简单的实体审计字段(例如 @CreatedDate
类型 Long
作为这里提到 http://docs.spring.io/spring-data/commons/docs/current/reference/html/#auditing.annotations)
此处讨论了 Neo4j 2.0 的解决方案:Audits with Spring Data Neo4j。但是对于版本 4,class 似乎已经在发行版中消失了。
我假设必须将事件侦听器添加到 Neo4j 才能填充这些字段。但是我在 spring-data-neo4j 发行版的任何地方都找不到 @EnableMongoAuditing
(MongoDB) 和 @EnableJpaAuditing
(JPA) 的 neo4j 副本。
这是否意味着我必须忽略 Neo4j 上这个特定的 Spring 数据功能?还有其他选择吗?
@Polyakoff SDN 4 当前不支持公共库中的注释。为了解决这个问题,我必须创建一个 Spring bean 来监听保存前的事件,如下所示:
@Bean
ApplicationListener<BeforeSaveEvent> beforeSaveEventApplicationListener() {
return new ApplicationListener<BeforeSaveEvent>() {
@Override
public void onApplicationEvent(BeforeSaveEvent event) {
event.getEntity().setCreatedDate(System.currentTimeMillis());
}
};
}