@EnableMongoAuditing 和 @CreatedDate 审计在 Spring Boot 2.4.3 中不起作用 [英] @EnableMongoAuditing and @CreatedDate Auditing not working in Spring Boot 2.4.3

查看:16
本文介绍了@EnableMongoAuditing 和 @CreatedDate 审计在 Spring Boot 2.4.3 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注这个例子 https://github.com/hantsy/spring-reactive-sample/blob/master/boot-exception-handler/src/main/java/com/example/demo/DemoApplication.java...这是有效的——在创建时设置 createDate MongoDB 字段.那里的版本是 2.1.6.RELEASE.但是,当我将其升级到 2.4.2 时,不再设置 createDate.没有警告,似乎只是停止工作了.

I'm following this example https://github.com/hantsy/spring-reactive-sample/blob/master/boot-exception-handler/src/main/java/com/example/demo/DemoApplication.java ...which works -- sets the createDate MongoDB field on creation. The version there is 2.1.6.RELEASE. However, when I upgrade this to 2.4.2, createDate is no longer set. There are no warnings, it seems just to have stopped working.

模型类是:

@Document
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
class Post {

    @Id
    private String id;
    private String title;
    private String content;

    @CreatedDate
    private LocalDateTime createdDate;
    @Version
    private Integer version;
}

此外,还设置了 MongoDB 审计:

Also, MongoDB auditing is set:

@SpringBootApplication
@EnableMongoAuditing
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

这是一个已知问题吗?我找不到任何关于此的迁移说明.如何在最新的 Spring Boot 版本中启用审计?

Is this is a known issue by any chance? I couldn't find any migration notes on this. How to enable auditing in the latest Spring Boot version?

更新:

看起来它工作的最新版本是 spring-boot-starter-parent 2.3.7.RELEASE.将其切换到 2.4.0 时停止工作.

Looks like the latest version where it worked is with spring-boot-starter-parent 2.3.7.RELEASE. Stops working when switch this to 2.4.0.

推荐答案

通过使用新的 @EnableReactiveMongoAuditing 注释解决,加上一个 bean 之类的

Resolved by using the new @EnableReactiveMongoAuditing annotation, plus a bean like

@Bean
public ReactiveAuditorAware<String> auditorProvider() {
    return () -> Mono.just("Me");
}

该问题可能与我使用 @EnableReactiveMongoRepositories

这篇关于@EnableMongoAuditing 和 @CreatedDate 审计在 Spring Boot 2.4.3 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆