MongoDB Error

时间:2021-01-06 15:14:07

①,org.springframework.core.convert.ConverterNotFoundException: No converter found capable of     converting from type org.joda.time.LocalDate to type java.lang.String
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:475)

at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:175)

at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:154)

解决方案:converter.afterPropertiesSet();

MappingMongoConverter converter = new MappingMongoConverter(mongoDbFactory, context);
converter.setTypeMapper(mapper);
converter.setCustomConversions(new CustomConversions(Arrays.asList(new TimeZoneReadConverter(),new TimeZoneWriteConverter())));
converter.afterPropertiesSet();
MongoTemplate template = new MongoTemplate(mongoDbFactory, converter);