我正在尝试使用基于注释的方法来使用spring-data-elasticsearch审核我的Elasticsearch文档。在实施我的课程/设置时,我遵循了JPA指南。
我的代码如下:
@Configuration
@EnableJpaAuditing
public class SpringSecurityAuditorAwareConfiguration {
@Bean
public AuditorAware<String> auditorProvider() {
return new SpringSecurityAuditorAware();
}
}
public class SpringSecurityAuditorAware implements AuditorAware<String> {
public Optional<String> getCurrentAuditor() {
return Optional.ofNullable(SecurityContextHolder.getContext())
.map(SecurityContext::getAuthentication)
.filter(Authentication::isAuthenticated)
.map(Authentication::getPrincipal)
.map(User.class::cast)
.map(User::getUsername);
}
}
@Document(indexName = "myEntity", type = "myEntityType")
public class MyEntity {
@Id
private String id;
@CreatedBy
protected String createdBy;
@CreatedDate
protected OffsetDateTime createdDate;
@LastModifiedBy
protected String lastModifiedBy;
@LastModifiedDate
protected OffsetDateTime lastModifiedDate;
public void setDictionaryId(DictionaryId dictionaryId) {
this.dictionaryId = dictionaryId;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public OffsetDateTime getCreatedDate() {
return createdDate;
}
public void setCreatedDate(OffsetDateTime createdDate) {
this.createdDate = createdDate;
}
public String getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public OffsetDateTime getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(OffsetDateTime lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
不幸的是,当我保存一个新实例时,属性始终设置为null。 spring-data-elasticsearch是否支持基于注释的方法?
否,Spring Data Elasticsearch当前不支持此功能。
请create a ticket添加对此的支持,这绝对是值得拥有的功能。