我正在使用带有弹性搜索的弹簧数据。 My Repository类有一个方法来获取索引中的最新插入。
Product findTop1ByOrderByIdDesc();
由于此失败,出现以下异常。
java.lang.NullPointerException:null at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.queryForPage(ElasticsearchTemplate.java:307) 〜[spring-data-elasticsearch-2.0.1.RELEASE.jar:na] at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.queryForObject(ElasticsearchTemplate.java:251) 〜[spring-data-elasticsearch-2.0.1.RELEASE.jar:na] at org.springframework.data.elasticsearch.repository.query.ElasticsearchPartQuery.execute(ElasticsearchPartQuery.java:78) 〜[spring-data-elasticsearch-2.0.1.RELEASE.jar:na] at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482) 〜[spring-data-commons-1.12.1.RELEASE.jar:na] at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460) 〜[spring-data-commons-1.12.1.RELEASE.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 〜[spring-aop-4.3.0.RC2.jar:4.3.0.RC2] at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) 〜[spring-data-commons-1.12.1.RELEASE.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 〜[spring-aop-4.3.0.RC2.jar:4.3.0.RC2] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 〜[spring-aop-4.3.0.RC2.jar:4.3.0.RC2] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 〜[spring-aop-4.3.0.RC2.jar:4.3.0.RC2] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) 〜[spring-aop-4.3.0.RC2.jar:4.3.0.RC2] at com.sun.proxy。$ Proxy92.findTop1ByOrderByIdDesc(未知来源) 〜[NA:NA]
我调试了spring-data代码,发现该方法的'query'为null
ElasticsearchTemplate.queryForPage
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
尝试产品findTopByOrderByIdDesc();