2017-04-13 6 views
0

私は春のデータの監査を実装しています。以下は私の設定ファイルここでSpring JPA監査が呼び出されない

@Configuration 
@ComponentScan(basePackages = "com.myapplication.test") 
@EnableWebMvc 
@EnableTransactionManagement 
@EnableJpaRepositories(basePackages = "com.myapplication.test.repository") 
@EnableJpaAuditing(auditorAwareRef = "auditorProvider", dateTimeProviderRef = "dateTimeProvider") 
@EnableSpringDataWebSupport 
public class ApplicationConfiguration { 

    private static final Logger loggger = Logger.getLogger(ApplicationConfiguration.class); 

    @Autowired 
    private ConfigurationProperties configProps; 

    @Bean("auditorProvider") 
    public AuditorAware<Integer> auditorProvider() { 
     return() -> { 
      AuthenticationToken authentication = (AuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); 
      return (authentication != null && authentication.isAuthenticated()) ? authentication.getUser().getUserId() : null; 
     }; 
    } 

    @Bean 
    public DateTimeProvider dateTimeProvider() { 
     return() -> GregorianCalendar.from(ZonedDateTime.now()); 
    } 

} 

@MappedSuperclass 
@EntityListeners(AuditingEntityListener.class) 
public abstract class BaseEntity { 

    @JsonIgnore 
    @Column(name = "created_by", updatable = false) 
    private Integer createdBy; 

    @JsonIgnore 
    @CreationTimestamp 
    @Temporal(TemporalType.TIMESTAMP) 
    @Column(name = "created_on", updatable = false) 
    private Date createdOn; 

    @JsonIgnore 
    @Column(name = "last_updated_by") 
    private Integer updatedBy; 

    @JsonIgnore 
    @UpdateTimestamp 
    @Temporal(TemporalType.TIMESTAMP) 
    @Column(name = "last_updated_on") 
    private Date updatedOn; 

} 

auditorProviderは春のセキュリティコンテキストからユーザIDを取得しているスーパークラスの私のエンティティです。私はspring-security-oauth2を使用しました。私は監査の方法が呼び出さ取得されていません(デバッグ中)および作成/更新フィールドがテーブルで更新されていないエンティティを保存するとライブラリのバージョン以下

は私が

<spring.version>4.3.6.RELEASE</spring.version> 
<hibernate.version>5.2.9.Final</hibernate.version> 
<springsecurity.version>4.1.4.RELEASE</springsecurity.version> 
<springsecurityoauth2.version>2.0.12.RELEASE</springsecurityoauth2.version> 

を持っています。

答えて

0

代わりに休止状態の注釈を使用して、あなたのような春のデータのものを使用する必要があります。

このチュートリアルで指定されている。これは常に、私のために働いた
@Column(name = "created_date", nullable = false, updatable = false) 
@CreatedDate 
private long createdDate; 

@Column(name = "modified_date") 
@LastModifiedDate 
private long modifiedDate; 

Jpa Auditing