java - 如何防止 Spring 创建一个只是要扩展的“抽象”泛型类型存储库?
问题描述
如果我想做这样的事情:
public interface LongIdRepo<T> extends PagingAndSortingRepository<T, Long> {}
因为我想像这样扩展它:
public interface MyRepo extends LongIdRepo<My> {}
这是不可能的,因为:
org.springframework.beans.factory.BeanCreationException:创建名为“longIdRepo”的bean时出错:调用init方法失败;嵌套异常是 java.lang.IllegalArgumentException: Not a managed type: class java.lang.Object
有什么方法可以让 Spring 忽略 LongIdRepo bean 创建?
解决方案
试试这个@NoRepositoryBean注解
@NoRepositoryBean
public interface LongIdRepo<T> extends PagingAndSortingRepository<T, Long> {}