Spring Data JPA以编程方式启用审计

时间:2014-01-24 11:07:05

标签: configuration spring-data-jpa auditing

如何在<jpa:auditing auditor-aware-ref="yourAuditorAwarebean" />班级中以编程方式执行以下操作:@Configuration? 弹簧xml配置是否必须执行此操作?

参考:http://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/reference/html/jpa.repositories.html#d0e2427

1 个答案:

答案 0 :(得分:2)

自Spring Data JPA 1.5(link to documentation

以来,现在支持用于审计的Java Config

在任何配置类上用<jpa:auditing auditor-aware-ref="yourAuditorAwarebean" />注释替换@EnableJpaAuditing

E.g:

@Configuration
@EnableJpaAuditing
class Config {

  @Bean
  public AuditorAware<AuditableUser> yourAuditorAwarebean() {
    return new YourAuditorAwareImpl();
  }
}