私は春のブートを使用しているため、設定にxmlファイルを使用していません。 私は、MongoRepositoriesを使ってデータを保存しながら、createdDate、lastModifiedDateなどを保存するためにEnableMongoAuditingを行う必要があります。mongodbの保存用の春ブートでの監査createdDate、lastModifiedDate、createdBy、lastModifiedBy
私のモデルクラス
@Component
@Document(collection = "CAPPING")
public class TemporaryCapping extends BaseEntity {
@Field("contract_id")
private BigInteger contractId;
@Field("period_id")
private BigInteger periodId;
@Field("user_id")
private BigInteger userId;
@Field("amount")
private Double amount;
@Field("type_of_capping")
private TypeOfCapping typeOfCapping;
public BigInteger getContractId() {
return contractId;
}
public void setContractId(BigInteger contractId) {
this.contractId = contractId;
}
public BigInteger getPeriodId() {
return periodId;
}
public void setPeriodId(BigInteger periodId) {
this.periodId = periodId;
}
public BigInteger getUserId() {
return userId;
}
public void setUserId(BigInteger userId) {
this.userId = userId;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
public TypeOfCapping getTypeOfCapping() {
return typeOfCapping;
}
public void setTypeOfCapping(TypeOfCapping typeOfCapping) {
this.typeOfCapping = typeOfCapping;
}
}
public class BaseEntity implements Serializable{
@Id
@Indexed(unique = true)
private BigInteger id;
@CreatedDate
private DateTime createdDate;
@Field("modified_date")
private BigInteger modifiedDate;
public BigInteger getId() {
return id;
}
public void setId(BigInteger id) {
this.id = id;
}
public DateTime getCreatedDate() {
return createdDate;
}
public void setCreatedDate(DateTime createdDate) {
this.createdDate = createdDate;
}
public BigInteger getModifiedDate() {
return modifiedDate;
}
public void setModifiedDate(BigInteger modifiedDate) {
this.modifiedDate = modifiedDate;
}
私はCREATEDATEを保存するための@CreateDate注釈を使用していました。 及びIは日時
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.7</version>
</dependency>
ばねデータのMongoDBも依存性で添加されるためjodatime依存関係を使用しています。
これは私のメインのアプリケーションクラス日付はデータベースに保存されて取得されていないとして、私はこのimpelmentationに間違っている
@SpringBootApplication
@EnableMongoAuditing
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
のですか? また、私は@createdByを保存するためにAuditorAware beanを書く必要があることを知っていますが、今はcreatedByを保存しようとしています。
@EnableMongoAuditingはどこで使用する必要がありますか?
はどこMongoConfigurationクラスが使用されない(次の@Configuration注釈に)構成のどこにでも配置することができますか? –
アノテーション@Configurationは、クラスがXMLと同様の設定であるが、Javaコードであることを示しています。多くのコンフィグレーションクラスを持つことができます。パッケージクラスにpackageScanを置くだけで、そこにコンフィグレーションクラスがあります。 – Cyva
Springスキャンアプリにパッケージスキャンを追加する方法。 @SpringBootApplication(scanBasePackages = {"com.some.package"}) – Cyva