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
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
- 源码类
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文件
- 方案一
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="mongoMoxydomainConverter"
class="org.springframework.data.mongodb.core.convert.MappingMongoConverter">
<constructor-arg index="0" ref="mongoDbFactory" />
<constructor-arg index="1">
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
</constructor-arg>
<property name="mapKeyDotReplacement" value="\\+"/>
</bean>
</beans>
@SpringBootApplication
@ImportResource("classpath:mongo.xml")