Spring Boot MongoDB Map的Key包含点

spring boot contains dots but no replacement was configured! Make sure map keys don't contain dots in the first place or configure an appropriate replacement!

  • Spring Boot版本1.5.6.RELEASE

    org.springframework.boot
    spring-boot-starter-data-mongodb

  • 源码类MappingMongoConverter.java
protected String potentiallyEscapeMapKey(String source) {
    if(!source.contains(".")) {
        return source;
    } else if(this.mapKeyDotReplacement == null) {
        throw new MappingException(String.format("Map key %s contains dots but no replacement was configured! Make sure map keys don't contain dots in the first place or configure an appropriate replacement!", new Object[]{source}));
    } else {
        return source.replaceAll("\\.", this.mapKeyDotReplacement);
    }
}
  • 解决方案
    • 方案一
      替换key中的.
      例如 1.5米 入库时改成1_5米
    • 方案二
      • 创建mongo.xml文件


    
    
    
        
    
    
    

@SpringBootApplication
@ImportResource("classpath:mongo.xml")

你可能感兴趣的:(Spring Boot MongoDB Map的Key包含点)