Map key action.type contains dots but no replacement was configured! Make sure map keys don’t contain dots in the first place or configure an appropriate replacement!
网上资料说是Mongodb数据写入key包含“.”,debug出来还真的有。
配置转化器
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.convert.DbRefResolver;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
@Configuration
public class MongoDBConfig {
@Bean
public MappingMongoConverter mappingMongoConverter(
MongoDbFactory mongoDbFactory,
MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext)
throws Exception {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContext);
converter.setMapKeyDotReplacement("_");
converter.afterPropertiesSet();
return converter;
}
}
这样数据写入的时候会以下划线替代