我正在为我的应用程序使用Spring Data rest。
我在我的存储库中使用以下方法。
public interface TestRepository() extends BaseRepository<TestTerm, Integer>{
@Query("select distinct tt.term from TestTerm")
List<String> findDistinctTerm();
}
当我执行上述方法时。我收到了以下错误
PersistentEntity must not be null
与Spring Data Rest (SDR ) bug? Persistent Entity Must not be null
相关的问题我该如何解决这个问题?
我是否必须为此单独编写实现?如果有的话,任何人都为我提供了这个例子吗?
更新: -
我试过这样的
方法1: -
@Query("select DISTINCT term from ForbiddenTerm")
List<TestTerm> findDistinctByTerm();
错误: -
{ &#34;原因&#34;:null, &#34; message&#34;:&#34; PersistentEntity不能为空!&#34; }
方法2: -
List<TestTerm> findDistinctByTerm();
错误: -
... 154 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.repository.support.Repositories]: Factory method 'repositories' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'forbiddenTermRepository': Invocation of init method failed; nested exception is java.util.NoSuchElementException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
... 175 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'forbiddenTermRepository': Invocation of init method failed; nested exception is java.util.NoSuchElementException
答案 0 :(得分:0)
您需要更改界面名称,如下所示:
@Repository
public interface TestTermRepository() extends BaseRepository<TestTerm, Integer>{
@Query("select distinct tt.term from TestTerm")
List<String> findDistinctTerm();
}
您还需要添加@Repository注释