当我想扩展SimpleJpaRepository这样的界面时,我正在使用Spring Boot:

public interface BaseRepository<T, ID extends Serializable> extends JpaRepository<T, ID>{}

和这个实现:
public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements BaseRepository<T, ID>
{
    private final EntityManager entityManager;

    public BaseRepositoryImpl(Class<T> domainClass, EntityManager entityManager)
    {
        super(domainClass, entityManager);
        this.entityManager = entityManager;
    }
}

我收到以下错误:
Could not autowire. No beans of 'Class<T>' type found.

我该如何解决?

最佳答案

创建扩展JpaRepository的接口(interface)

例如-

public interface Repository extends JpaRepository<Entity,Integer>,RepositoryCustom // this is our custom repository{


}

存储库定制是一个接口(interface)
public interface RepositoryCustom {


    List<Entity> getAll(); // define the method signature here


}

实现自定义界面
@Transactional
public class RepositoryImpl implements  RepositoryCustom{

    @PersistenceContext // this will inject em in your class
    private EntityManager entityManager;

    write the method body and return

}

10-05 22:47
查看更多