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

前端之家收集整理的这篇文章主要介绍了为什么我在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)
    …

在这里我的配置:

public class MongoDBConverters {

    public static class DateToLocalDateConverter 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;
}
原文链接:https://www.f2er.com/spring/431680.html

猜你在找的Spring相关文章