没有找到java.util.Date的映射元数据

时间:2017-01-15 13:56:13

标签: mongodb spring-data-mongodb spring-data-rest

我使用spring-boot + spring-data-rest + spring-data-mongodb,我有一个通过存储库公开的类,我最近从1.3.7升级到1.4。 3发布Spring Boot。

问题是如果我将字段createdDate保留为可用...我在检查API

时收到以下错误

去年我有一个类似的项目,它在Spring Boot 1.3.2上运行良好,没有必要实现一些自定义解决方案或配置其他东西。

稍后编辑刚刚降级为1.3.2 ......同样的错误......

"找不到java.util.Date的映射元数据"

public class SomeMessage {

@Id
private String id; 

private Map<String,String> messageDetails;

private String replyToId;

private String contactFormId;

//@CreatedDate
private Date createdDate;

//...getters, setters, what not

}

稍后编辑2 ...完整堆栈跟踪

org.springframework.data.mapping.model.MappingException: No mapping metadata found for java.util.Date
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:229) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1197) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.access$200(MappingMongoConverter.java:79) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1145) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:871) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:284) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:272) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:322) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:272) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:232) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:192) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:188) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:79) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.MongoTemplate$ReadDbObjectCallback.doWith(MongoTemplate.java:2295) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1949) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1767) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1750) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:624) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.findAll(SimpleMongoRepository.java:357) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.findAll(SimpleMongoRepository.java:219) ~[spring-data-mongodb-1.9.6.RELEASE.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_72]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_72]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_72]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_72]

2 个答案:

答案 0 :(得分:3)

您缺少POJO类的@Document注释。

来自docs

  

@Document - 在类级别应用以指示此类是a   映射到数据库的候选者。您可以指定的名称   将存储数据库的集合。

更新:虽然它不应该在没有@Document的情况下工作,因为它不是必需的注释。

答案 1 :(得分:1)

我在消息中遇到类似的问题:

  

未找到类org.bson.types.ObjectId的映射元数据

我的实体有@Document注释。 该实体中有一个字段Set<ObjectId>并带有@DBRef(lazy = true)注释。 删除@DBRef注释解决了我的问题。