我刚接触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)
如果您使用命名空间配置,则存储库基础结构会尝试通过扫描在我们发现存储库的包下面的类来自动检测自定义实现。
实现是否在存储库的子包中? - Evgeni Dimitrov