如何使用Java Config配置审核

编程入门 行业动态 更新时间:2024-10-19 00:25:26
本文介绍了如何使用Java Config配置审核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用Spring Data JPA实施基本审核.从这个问题中,我得知还没有可以使用注释启用审核.所以我在src/main/resources中有以下applicationContext.xml文件:

I'm trying to implement basic auditing using Spring Data JPA. From this question I learned that it is not yet possible to enable auditing using an annotation. So I have the following applicationContext.xml file in src/main/resources:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="www.springframework/schema/beans" xmlns:xsi="www.w3/2001/XMLSchema-instance" xmlns:jpa="www.springframework/schema/data/jpa" xsi:schemaLocation="www.springframework/schema/beans www.springframework/schema/beans/spring-beans.xsd www.springframework/schema/data/jpa www.springframework/schema/data/jpa/spring-jpa.xsd"> <jpa:auditing /> </beans>

我已经将@ImportResources("classpath:/applicationContext.xml")添加到了我的Java Config文件中.

I have added the @ImportResources("classpath:/applicationContext.xml") to my Java Config file.

在我的AbstractEntity(是@MappedSuperClass)上,我具有以下内容:

On my AbstractEntity(which is a @MappedSuperClass) I have the following:

@MappedSuperclass public abstract class AbstractEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Version private Integer version; @CreatedDate private Date createdDate; @LastModifiedDate private Date lastModifiedDate; // GETTERS AND SETTERS }

已导入java.util.Date的位置.我也尝试过使用JodaTime,但没有任何变化.

Where java.util.Date has been imported. I have also tried with JodaTime but no change.

据我所知,此配置应足以启用日期审核.我不需要进行@CreatedBy或@LastModifiedBy审核,因此我认为我不需要AuditAware Bean ...即使如此,我也尝试添加它但也没有运气.

As far as I can tell this configuration should be sufficient to enable the auditing for dates. I have no need for the @CreatedByor @LastModifiedBy audits, so I don't think I need an AuditAware bean...even so, I have tried adding it but also without luck.

如何进行基本审核?

推荐答案

首先,Spring Data JPA 1.5 M1附带了@EnableJpaAuditing,因此,如果能够升级到此版本,则不需要额外的XML文件.版本.

First of all, Spring Data JPA 1.5 M1 ships with @EnableJpaAuditing so that you don't need the extra XML file if you're able to upgrade to this version.

似乎您在JPA配置(通​​常是orm.xml配置文件)中缺少AuditingEntityListener的声明.请参阅参考文档了解详情.

It seems like you're missing the declaration of the AuditingEntityListener in the JPA config (usually the orm.xml config file). See the reference documentation for details.

更多推荐

如何使用Java Config配置审核

本文发布于:2023-11-28 15:23:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642942.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   Java   Config

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!