我正在从事Spring Boot 2.x项目。我有很多实体,并且必须为每个实体创建一个存储库接口。
是否可以创建一个通用的Crud存储库而不是创建许多存储库?
我尝试了以下操作:
package auto.nicu.repository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface ModelRepository<T> extends PagingAndSortingRepository<T, Integer> {
Page<T> findAll(Pageable pageable);
}
我正在尝试像这样注入它:
@Autowired
private ModelRepository<ActionType> repository;
我收到此错误:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'actionServiceImpl':
Unsatisfied dependency expressed through field 'repository'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'modelRepository': Invocation of init method failed;
nested exception is java.lang.IllegalArgumentException: Not a managed type: class java.lang.Object