英文:
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<MyEntity, Long> {
}
As per documentation I can activate Spring Data JPA repositories simply by adding
<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 class="x.y.z.MyBean">
<constructor-arg name="repository" ref="XXX" />
</bean>
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 的文档参考
答案2
得分: 1
<bean class="x.y.z.MyBean">
<constructor-arg name="repository" ref="<with qualified path>MyJpaRepo " />
</bean>
英文:
<bean class="x.y.z.MyBean">
<constructor-arg name="repository" ref="<with qualified path>MyJpaRepo " />
</bean>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论