如何防止 Spring 创建一个 "abstract" 泛型存储库只是为了扩展?
How to to prevent Spring to create an "abstract" generic type repository that is just to be extended?
如果我想做这样的事情:
public interface LongIdRepo<T> extends PagingAndSortingRepository<T, Long> {}
因为我想像这样扩展它:
public interface MyRepo extends LongIdRepo<My> {}
这是不可能的,因为:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'longIdRepo': Invocation of init method
failed; nested exception is java.lang.IllegalArgumentException: Not a
managed type: class java.lang.Object
有什么方法可以让 Spring 忽略 LongIdRepo bean 的创建吗?
试试这个 @NoRepositoryBean 注释
@NoRepositoryBean
public interface LongIdRepo<T> extends PagingAndSortingRepository<T, Long> {}
如果我想做这样的事情:
public interface LongIdRepo<T> extends PagingAndSortingRepository<T, Long> {}
因为我想像这样扩展它:
public interface MyRepo extends LongIdRepo<My> {}
这是不可能的,因为:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'longIdRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class java.lang.Object
有什么方法可以让 Spring 忽略 LongIdRepo bean 的创建吗?
试试这个 @NoRepositoryBean 注释
@NoRepositoryBean
public interface LongIdRepo<T> extends PagingAndSortingRepository<T, Long> {}