【问题标题】:Spring data inject repository without explicit type没有显式类型的 Spring 数据注入存储库
【发布时间】:2019-06-22 12:33:59
【问题描述】:

我有一项服务需要使用Neo4jRepository(spring data 的常规存储库提供程序)。

public class SomeServiceBean<T>{

     @Autowired
     private Neo4jRepository<T,Long> Neo4jRepository;

}

这个类会产生 en 错误:

 expected single matching bean but found 2: systemUserRepository,systemClaimRepository

问题在于systemClaimRepositorysystemUserRepositoryNeo4jRepository&lt;T,Long&gt; 扩展为没有实现的bean。 Spring 将 systemClaimRepositorysystemUserRepository 视为 Neo4jRepository&lt;T,Long&gt;,因为它们正在扩展它。

有没有办法注入Neo4jRepository&lt;T,Long&gt;? 谢谢

【问题讨论】:

    标签: spring-data autowired


    【解决方案1】:

    不,这应该如何工作?

    您有两个匹配接口的 bean,而 Spring 不知道要注入哪个实现。

    【讨论】:

    • 嘿,谢谢,我和T一起来,T应该有所作为
    • 没有。因为 Java 泛型是一个编译时构造。他们在运行时不在那里。 baeldung.com/java-type-erasure
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-04
    • 2020-09-19
    • 2019-03-10
    • 1970-01-01
    • 2012-03-13
    相关资源
    最近更新 更多