Spring Data – 存储库 bean ID

huangapple go评论86阅读模式
英文:

Spring Data - Repository bean ID

问题

我不理解如何在Spring Data中显式地为存储库bean分配ID。

明确地说,假设我在包com.acme.repositories中定义了以下接口:

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

根据文档,我可以通过添加以下内容来激活Spring Data JPA存储库:

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

最后,假设在同一个上下文中我还有另一个bean,其构造函数需要传递一个JpaRepository。我会这样定义它:

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

现在,在XXX的位置应该使用什么?或者,更好的是,如何显式地为MyJpaRepo存储库bean分配一个ID呢?

谢谢!

英文:

I cannot understand how to explicitly assign an ID to a repository bean in Spring Data.

To be clear, suppose I defined the following interface in package com.acme.repositories

public interface MyJpaRepo extends JpaRespository&lt;MyEntity, Long&gt; {
}

As per documentation I can activate Spring Data JPA repositories simply by adding

&lt;jpa:repositories base-package=&quot;com.acme.repositories&quot; /&gt;

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

&lt;bean class=&quot;x.y.z.MyBean&quot;&gt;
	&lt;constructor-arg name=&quot;repository&quot; ref=&quot;XXX&quot; /&gt;
&lt;/bean&gt;

Now, what should I use in place of XXX? Or, even better, how can I explicitly assign an ID to the MyJpaRepo repository beans?

Thanks!

答案1

得分: 1

替代XXX,使用myJpaRepo

来源:Spring Data Jpa 仓库 ID 的文档参考

英文:

In place of XXX use myJpaRepo.

source: Spring Data Jpa document reference for repository id

答案2

得分: 1

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

英文:
&lt;bean class=&quot;x.y.z.MyBean&quot;&gt;
    &lt;constructor-arg name=&quot;repository&quot; ref=&quot;&lt;with qualified path&gt;MyJpaRepo &quot; /&gt;
&lt;/bean&gt;

huangapple
  • 本文由 发表于 2020年9月28日 02:50:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/64092125.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定