【发布时间】:2016-08-11 19:42:53
【问题描述】:
我在应用程序上使用 Spring Boot (1.3.3) 和基于注释的/JavaConfig 配置。 我有以下存储库接口:
@RepositoryRestResource(collectionResourceRel = "something", path = "something")
public interface SomethingRepository
extends CrudRepository<SomethingRepository, Long> {
}
我想做的是覆盖生成的存储库代理中某些方法的行为。我发现这样做的唯一方法是基于文档建议添加新的自定义方法(请参阅:Adding custom behavior to single repositories),因此我定义了以下接口:
public interface SomethingRepositoryCustom {
Something findOne(Long id);
}
...我添加了相应的实现:
public SomethingRepositoryImpl extends SimpleJpaRepository<Something, Long>
implements SomethingRepositoryCustom {
public SomethingRepositoryImpl(<Something> domainClass, EntityManager em) {
super(domainClass, em);
this.entityManager = em;
}
@Override
public Something findOne(Long id) {
System.out.println("custom find one");
// do whatever I want and then fetch the object
return null;
}
}
现在,如果我启动应用程序,我会收到以下错误:
... org.springframework.beans.BeanInstantiationException: 失败 实例化 [com.dummy.repositories.SomethingRepositoryImpl]:否 找到默认构造函数;嵌套异常是 java.lang.NoSuchMethodException: com.dummy.repositories.SomethingRepositoryImpl.() ...
问题: 如何解决 BeanInstantiationException?我假设我需要声明一个存储库工厂 bean,但我不确定如何覆盖 Spring Boot 配置。
【问题讨论】:
标签: java spring spring-boot spring-data