【发布时间】:2015-06-19 06:41:03
【问题描述】:
我是 Spring Data JPA 的新手。我试图为存储库创建一个自定义方法,但它确实引发了异常。这是我目前的实现:
public interface EmployeeRepository extends
CrudRepository<Employee, Long>,EmployeeRepositoryCustom {
}
@Repository
public interface EmployeeRepositoryCustom {
public void updateEmployee(String field, String value,long id);
}
public class EmployeeRepositoryImpl implements EmployeeRepositoryCustom {
@PersistenceContext
private EntityManager entityManager;
@Override
public void updateEmployee(String field, String value, long id) {
// Implementation goes here
}
}
这是我启动应用程序时发生的异常(我使用的是 Spring boot)。
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property updateEmployee found for type Employee!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
【问题讨论】:
-
来自文档:
If you use namespace configuration, the repository infrastructure tries to autodetect custom implementations by scanning for classes below the package we found a repository in.是 repo 子包中的实现吗? -
实现也在同一个包中
-
这应该可以正常工作。愿意分享一个显示错误的示例项目吗?
-
你的代码没问题。将其复制到新的 Spring Boot 项目works。您的应用程序中的其他内容正在导致问题。您是否尝试为所有存储库提供自定义实现?我在尝试为所有存储库提供自定义实现时遇到此错误。
标签: spring jpa spring-boot spring-data spring-data-jpa