Spring 是否有扩展JPA存储库并扩展另一个定义了抽象类的接口?

Spring 是否有扩展JPA存储库并扩展另一个定义了抽象类的接口?,spring,spring-boot,spring-data-jpa,Spring,Spring Boot,Spring Data Jpa,我想要一个EntityRepository从Crudepository接口和自定义的CustomizedRepository接口扩展而来,该接口定义了一个抽象类。可能吗 我现在想我可以有一个完整的位置定义为 public interface EntityRepository extends EntityRepositoryCustom, CrudRepository<Entity, String> { } public interface EntityRepository扩展了En

我想要一个EntityRepository从Crudepository接口和自定义的CustomizedRepository接口扩展而来,该接口定义了一个抽象类。可能吗

我现在想我可以有一个完整的位置定义为

public interface EntityRepository extends EntityRepositoryCustom, CrudRepository<Entity, String> {
}
public interface EntityRepository扩展了EntityRepositoryCustom,crudepository{
}
对于整个位置的习惯,我有

public interface EntityRepositoryCustom {
    public Page<Entity> findEntitisOnCondition(Entity t, Pageable pageable);
}
公共接口实体位置自定义{
公共页面查找身份条件(实体t,可分页);
}
使用EntityRepositoryCustomImpl

public class EntityRepositoryCustomImpl<Entity> extends SelfDefinedRepositoryImpl<Entity> {
    @Override
    protected String getSOmething() {
        ...
    }
}
public类EntityRepositoryCustomImpl扩展了SelfDefinedRepositoryImpl{
@凌驾
受保护的字符串getSOmething(){
...
}
}
自定义存储和自定义存储impl分别定义如下

public interface SelfDefinedRepository<T, ID extends Serializable>  extends CrudRepository<T, ID> {
    Page<T> findEntitisOnCondition(T t, Pageable pageable);
}
public接口自定义存储扩展了crudepository{
页面查找状态(T,可分页可分页);
}

公共抽象类SelfDefinedRepositoryImpl实现SelfDefinedRepository{
公共页面findEventsOnCondition(T,可分页,可分页){
...
getSomething();
...
}
受保护的抽象字符串getSomething();
}
这个想法失败了。有谁能帮助我实现一个存储库接口/实现,我可以拥有JPA存储库功能,也可以扩展我的自定义抽象类?谢谢。


这有助于解决您的问题。

您这样做的目的是什么?你只是想在抽象类中对你的常用方法进行分组并重用它们吗?@Amit,我正在尝试在抽象类中获得一个“通用搜索条件”函数。然后你可以使用组合而不是继承。你读了吗?你使用的是什么版本的Spring数据?它究竟是如何失败的?因为您有一个非抽象类用于自定义实现,所以层次结构中的抽象类实际上并不重要
public abstract class SelfDefinedRepositoryImpl<T, ID extends Serializable> implements SelfDefinedRepository<T, Serializable>{

    public Page<T> findEventsOnCondition(T t, Pageable pageable) {
        ...
        getSomething();
        ...
    }

    protected abstract String getSomething();

}