我的课如下
public abstract interface IGenRepository <T> {
public abstract List<T> getAll(String filter);
}
和
@Repository
public abstract class GenRepository<T> implements IGenRepository<T> {
protected abstract Class<T> myFunction();
@Override
public List<T> getAll(String filter) {
.......}}
所有这些类都是通用的,现在我想在项目中使用这些类
public interface IProductRepository extends IGenRepository<Product> {}
该类的含义是:
@Repository
public class ProductRepository extends GenRepository<Product> {}
在使用此类时,请按以下步骤使用:
@Autowired private IProductRepository iProductRepository;
有这个错误
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'productService': Unsatisfied dependency expressed through field 'iProductRepository';
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'org.tax.repositories.IProductRepository' available:
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
最佳答案
您没有实现IProductRepository
ProductRepository
类。
更改代码如下-
@Repository
public class ProductRepository implements IProductRepository extends GenRepository<Product> {}