@Configuration
public class ApplicationReadyListener implements ApplicationListener<ContextRefreshedEvent> {

  @Autowired
  MongoTemplate mongoTemplate;

  @Override
  public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
    MongoConverter converter = mongoTemplate.getConverter();
    if (converter.getTypeMapper().isTypeKey("_class")) {
      ((MappingMongoConverter) converter).setTypeMapper(new DefaultMongoTypeMapper(null));
    }
  }
}

参考:

Spring Boot 学习笔记:MongoTemplate 移除 _class 字段

相关文章:

  • 2021-11-03
  • 2022-12-23
  • 2021-07-02
  • 2021-11-29
  • 2021-11-20
  • 2021-09-03
  • 2022-01-06
猜你喜欢
  • 2022-12-23
  • 2021-09-14
  • 2022-02-09
  • 2022-12-23
  • 2021-12-12
  • 2021-11-18
  • 2021-06-06
相关资源
相似解决方案