一、解决SpringBoot MongoDB插入文档默认生成_class字段问题
@Configuration public class SpringMongoConfig{ @Bean public MongoTemplate mongoTemplate() throws Exception { //remove _class MappingMongoConverter converter = new MappingMongoConverter(mongoDbFactory(), new MongoMappingContext()); converter.setTypeMapper(new DefaultMongoTypeMapper(null)); MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory(), converter); return mongoTemplate; } }
二、spring boot 集成mongodb 开启事务
@Configuration public class TransactionConfig { @Bean MongoTransactionManager transactionManager(MongoDbFactory factory){ return new MongoTransactionManager(factory); } }