微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我在Spring Data MongoDB上得到“在实体类中找不到属性节点…将构造函数参数绑定到!”

尝试将JodaTime的LocalDate与Spring Data MongoDB和Spring 4一起使用,但我收到以下异常:

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Request processing Failed; nested exception is org.springframework.data.mapping.model.MappingException: No property node found on entity class com.th.model.Price to bind constructor parameter to!] with root cause
org.springframework.data.mapping.model.MappingException: No property node found on entity class com.th.model.Price to bind constructor parameter to!
    at org.springframework.data.mapping.model.PersistentEntityParameterValueProvider.getParameterValue(PersistentEntityParameterValueProvider.java:74)
    at org.springframework.data.mapping.model.SpELExpressionParameterValueProvider.getParameterValue(SpELExpressionParameterValueProvider.java:63)
    at org.springframework.data.convert.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:71)
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:249)
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:230)
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:190)
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:186)
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:77)
    at org.springframework.data.mongodb.core.MongoTemplate$ReadDbObjectCallback.doWith(MongoTemplate.java:2121)
    at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1805)
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1628)
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1611)
    at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:535)
    at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:526)
    at com.th.model.Company.getPrices(Company.java:255)
    at com.th.controller.Home.getPrices(Home.java:32)
    …

在这里我的配置:

dbname="th" host="localhost"/>

custom-converters>
    etoLocalDateConverter"/>
    etoDateConverter"/>
    custom-converters>
public class MongoDBConverters {

    public static class DatetoLocalDateConverter implements ConverteretoDateConverter implements Converter
最佳答案
显然我不能有这样的构造函数

public Price(String companyId,JsonNode node) {
        this.companyId = companyId;

        if(node != null) {
            this.date = Tools.getLocalDate(node.get("Date").getTextValue());
            this.closePrice = Double.parseDouble(node.get("Close").getTextValue());
            this.volume = Double.parseDouble(node.get("Volume").getTextValue());
        }
}

具有直接分配工作的正常工作:

public Price(String companyId,LocalDate date,double closePrice,double volume) {
    this.companyId = companyId;
    this.date = date;
    this.closePrice = closePrice;
    this.volume = volume;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐