美文网首页
Caused by: org.springframework.d

Caused by: org.springframework.d

作者: 梦想又照进现实 | 来源:发表于2019-07-13 22:30 被阅读0次

    环境情况

    ES版本

    {
      "name" : "TEAsXa0",
      "cluster_name" : "elasticsearch_apple",
      "cluster_uuid" : "v0c634MwS4yoIbzJyT0lTA",
      "version" : {
        "number" : "6.8.1",
        "build_flavor" : "oss",
        "build_type" : "tar",
        "build_hash" : "1fad4e1",
        "build_date" : "2019-06-18T13:16:52.517138Z",
        "build_snapshot" : false,
        "lucene_version" : "7.7.0",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
    }
    

    Spring boot data

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
            </dependency>
    

    具体使用spring-boot-starter-data-elasticsearch:2.1.6.RELEASE版本

    报错如下:

    Caused by: org.springframework.data.mapping.PropertyReferenceException: No property ss found for type Long! Traversed path: Book.saleCnt.
        at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
        at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:382) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
        at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
        at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:392) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
        at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:416) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
        at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
        at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:311) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
        at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324) ~[na:1.8.0_181]
        at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:293) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
        at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:276) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
    

    对应org.springframework.data.mapping.PropertyPath.from(源码:

    public static PropertyPath from(String source, TypeInformation<?> type) {
            Assert.hasText(source, "Source must not be null or empty!");
            Assert.notNull(type, "TypeInformation must not be null or empty!");
            return (PropertyPath)CACHE.computeIfAbsent(PropertyPath.Key.of(type, source), (it) -> {
                List<String> iteratorSource = new ArrayList();
                Matcher matcher = isQuoted(it.path) ? SPLITTER_FOR_QUOTED.matcher(it.path.replace("\\Q", "").replace("\\E", "")) : SPLITTER.matcher("_" + it.path);
    
                while(matcher.find()) {
                    iteratorSource.add(matcher.group(1));
                }
    
                Iterator<String> parts = iteratorSource.iterator();
                PropertyPath result = null;
                Stack current = new Stack();
    
                while(parts.hasNext()) {
                    if (result == null) {
                        result = create((String)parts.next(), it.type, current);
                        current.push(result);
                    } else {
                        current.push(create((String)parts.next(), current));
                    }
                }
    
                if (result == null) {
                    throw new IllegalStateException(String.format("Expected parsing to yield a PropertyPath from %s but got null!", source));
                } else {
                    return result;
                }
            });
        }
    
    

    在对实体做Mapping时候是根据属性名字来映射Repository中的方法的,如下

    public interface BookRepository extends ElasticsearchRepository<Book, String> {
    

    方法名称中必须和实体属性对应,除了关键字And、Or、Not、Like等,类似JPA的方式,修改错误字母程序test通过。

    相关文章

      网友评论

          本文标题:Caused by: org.springframework.d

          本文链接:https://www.haomeiwen.com/subject/afhvkctx.html