我正在使用100多个实体(使用JHipster)设置一个新的Spring Boot API,我的问题是:鉴于我有一组存储库层方法,我希望所有存储库都能够调用这些方法。
我已经尝试使所有.*Repository
接口扩展为.*RepositoryQuery
(“ RepositoryQuery”是我的默认自定义接口名称后缀),然后使用特定于实体的{{1} }类。请注意,所有.*RepositoryQueryImpl
类都扩展了名为.*RepositoryQueryImpl
的泛型实现类。
请注意,给定正则表达式中的“。*”代表我的持久实体集中的任何实体。
下面显示的具有关键类和接口的代码:
BaseRepositoryQueryImpl
public interface BaseRepositoryQuery<T, PK> {
public List<T> retrieveByCriteria(T searchCriteria);
// other methods go here ...
}
public class BaseRepositoryQueryImpl<T, PK> implements BaseRepositoryQuery<T, PK> {
@PersistenceContext
private EntityManager em;
private Class<T> businessClass;
protected BaseRepositoryQueryImpl(Class<T> businessClass) {
this.businessClass = businessClass;
}
public List<T> retrieveByCriteria(T searchCriteria) {
// ...
}
// other methods go here ...
}
界面:RepositoryQuery
public interface SomeEntityRepositoryQuery extends BaseRepositoryQuery<SomeEntity, Long> {}
public class SomeEntityRepositoryQueryImpl extends BaseRepositoryQueryImpl<SomeEntity, Long> implements SomeEntityRepositoryQuery {
public SomeEntityRepositoryQueryImpl(Class<SomeEntity> businessClass) {
super(businessClass);
}
public SomeEntityRepositoryQueryImpl() {
super(SomeEntity.class);
}
}
界面:Repository
@Repository
public interface SomeEntityRepository extends SomeEntityRepositoryQuery, JpaRepository<SomeEntity, Long> {
// other methods go here...
}
请注意,“ SomeEntity”可以是我的一组持久实体中的任何实体(很抱歉,它是如此明显)。此外,我已经将配置设置为:
@Autowired
private SomeEntityRepository someEntityRepository;
到目前为止,我所拥有的(正在运行的maven)是一个错误日志:
@Configuration
@EnableJpaRepositories("<my base jpa repositories package here>")
我怀疑该错误可能与Spring存储库命名有关,并且我已经尝试查找其他SO线程,但是没有一个适合这种情况。
答案 0 :(得分:0)
请签入BaseRepositoryQuery ..您可能使用的错误字段。这就是为什么它对此抱怨的原因。