加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

为什么我在Spring Data MongoDB上得到“在实体类中找不到属性节

发布时间:2020-12-15 01:39:40 所属栏目:大数据 来源:网络整理
导读:尝试将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.springframew

尝试将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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读