我试图在Spring中添加自定义存储库方法,如下面的文档中所示:
并在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!
我很难理解。这里发生了什么?