這可能類似於其他幾個已經問過的問題,但我找不到確切的答案。我試圖建立在Spring JPASpring JPA通用基礎知識庫
基本接口的通用基礎類:
@NoRepositoryBean
public interface GenericRepository <T, ID extends Serializable>
{
public T handleCustom(String id);
}
實現類:
@SuppressWarnings("serial")
public class GenericRepositoryImpl<T, ID extends Serializable>
implements GenericRepository<T, ID>
{
@PersistenceContext
private EntityManager entityManager;
Class type;
public T handleCustom(String id)
{
Annotation[] ann = type.getAnnotations();
return null;
}
}
特定領域的類:
public interface DomainRepository
extends JpaRepository<Domain, String>,
GenericRepository<Domain, String>
{
}
實體:
@Entity
public class Domain extends ParentEntity
{
@Id
private String domainId;
private String domainName;
public Domain()
{
}
//setters getters
.....
}
配置文件:
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "com.rabbitmq.jpa")
public class JPAConfig
{
}
以下錯誤:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'domainRepository':
Invocation of init method failed;
nested exception is org.springframework.data.mapping.PropertyReferenceException:
No property handleCustom found for type Domain!
我在做什麼錯在這裏。
見http://docs.spring.io/spring-data/jpa/docs/1.7.2.RELEASE/reference/html/#repositories.custom-behaviour-for-all -repositories –