简体   繁体   English

Spring Data - 存储库 bean ID

[英]Spring Data - Repository bean ID

I cannot understand how to explicitly assign an ID to a repository bean in Spring Data.我无法理解如何在 Spring Data 中为存储库 bean 显式分配 ID。

To be clear, suppose I defined the following interface in package com.acme.repositories为了清楚com.acme.repositories ,假设我在包com.acme.repositories定义了以下接口

public interface MyJpaRepo extends JpaRespository<MyEntity, Long> {
}

As per documentation I can activate Spring Data JPA repositories simply by adding根据文档,我只需添加即可激活 Spring Data JPA 存储库

<jpa:repositories base-package="com.acme.repositories" />

Last, suppose that I have another bean in the same context which constructor requires a JpaRepository to be passed in. I would define it like that最后,假设我在同一个上下文中有另一个 bean,它的构造函数需要JpaRepository 。我会这样定义它

<bean class="x.y.z.MyBean">
    <constructor-arg name="repository" ref="XXX" />
</bean>

Now, what should I use in place of XXX ?现在,我应该用什么来代替XXX Or, even better, how can I explicitly assign an ID to the MyJpaRepo repository beans?或者,更好的是,如何为MyJpaRepo存储库 bean 显式分配 ID?

Thanks!谢谢!

In place of XXX use myJpaRepo .代替 XXX 使用myJpaRepo

source: Spring Data Jpa document reference for repository id来源: 存储库 ID 的 Spring Data Jpa 文档参考

<bean class="x.y.z.MyBean">
    <constructor-arg name="repository" ref="<with qualified path>MyJpaRepo " />
</bean>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM