自定义存储库在Spring中不起作用

时间:2017-11-20 17:05:57

标签: java spring spring-boot spring-data-jpa

我试图在Spring中添加自定义存储库方法,如下面的文档中所示:

https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.custom-implementations

并在Stack Overflow问题中:

How to add custom method to Spring Data JPA

它没有按预期工作。

我拿了存储库,定义为:

public interface ScreenshotRepository extends JpaRepository<Screenshot, UUID> {

并将其更改为

public interface ScreenshotRepository extends JpaRepository<Screenshot, UUID>, ScreenshotRepositoryCustom {

然后我创建了ScreenshotRepositoryCustom界面:

interface ScreenshotRepositoryCustom {
    void foo();
}

和实施:

class ScreenshotRepositoryCustomImpl implements ScreenshotRepositoryCustom {
    @Override
    public void foo() {
        System.out.println("Foo!!!");
    }
}

当我尝试启动spring应用程序时,收到此消息:

Error creating bean with name 'screenshotRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property foo found for type Screenshot!
我很难理解。这里发生了什么?

0 个答案:

没有答案