0
我得到了錯誤,並不知道在哪裏調試。春天+自定義轉換器+ Mongodb
ConverterNotFoundException:未發現轉換器能夠從類型@ javax.validation.constraints.NotNull的java.util.HashMap < @ javax.validation.constraints.NotNull java.lang.String中,@ javax.validation.constraints轉換的。 NOTNULL java.util.Date>鍵入java.lang.String中
我已經把我的應用程序上下文:
<mongo:mapping-converter id="mongoConverter" base-package="com.app">
<mongo:custom-converters>
<mongo:converter>
<bean class="com.app.util.converter.HashMapToStringConverter" />
</mongo:converter>
<mongo:converter>
<bean class="com.app.util.converter.StringToHashMapConverter" />
</mongo:converter>
</mongo:custom-converters>
</mongo:mapping-converter>
<bean class="org.springframework.data.mongodb.core.MongoTemplate" id="mongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
<constructor-arg name="mongoConverter" ref="mongoConverter"/>
</bean>
和我的轉換器之一是:
public class HashMapToStringConverter implements Converter<HashMap<String,Date>, String>{
@Override
public String convert(HashMap<String,Date> map) {
if(map==null){
throw new ConversionFailedException(TypeDescriptor.valueOf(HashMap.class),
TypeDescriptor.valueOf(String.class), map, null);
}
StringBuilder sb = new StringBuilder();
boolean first = true;
for(Map.Entry<String, ?> e: map.entrySet()){
if(!first){
sb.append(",");
first=!first;
}
sb.append(e.getKey());
sb.append("::");
sb.append(e.getValue());
}
return sb.toString();
}
}