• <bdo id='hcESA'></bdo><ul id='hcESA'></ul>

    <small id='hcESA'></small><noframes id='hcESA'>

      1. <tfoot id='hcESA'></tfoot>
      2. <legend id='hcESA'><style id='hcESA'><dir id='hcESA'><q id='hcESA'></q></dir></style></legend>
        <i id='hcESA'><tr id='hcESA'><dt id='hcESA'><q id='hcESA'><span id='hcESA'><b id='hcESA'><form id='hcESA'><ins id='hcESA'></ins><ul id='hcESA'></ul><sub id='hcESA'></sub></form><legend id='hcESA'></legend><bdo id='hcESA'><pre id='hcESA'><center id='hcESA'></center></pre></bdo></b><th id='hcESA'></th></span></q></dt></tr></i><div id='hcESA'><tfoot id='hcESA'></tfoot><dl id='hcESA'><fieldset id='hcESA'></fieldset></dl></div>

        如何检索给定域类的弹簧数据存储库实例?

        How to retrieve spring data repository instance for given domain class?(如何检索给定域类的弹簧数据存储库实例?)

          • <bdo id='flyAe'></bdo><ul id='flyAe'></ul>
              <tbody id='flyAe'></tbody>

            <small id='flyAe'></small><noframes id='flyAe'>

            <legend id='flyAe'><style id='flyAe'><dir id='flyAe'><q id='flyAe'></q></dir></style></legend>

              1. <tfoot id='flyAe'></tfoot>

              2. <i id='flyAe'><tr id='flyAe'><dt id='flyAe'><q id='flyAe'><span id='flyAe'><b id='flyAe'><form id='flyAe'><ins id='flyAe'></ins><ul id='flyAe'></ul><sub id='flyAe'></sub></form><legend id='flyAe'></legend><bdo id='flyAe'><pre id='flyAe'><center id='flyAe'></center></pre></bdo></b><th id='flyAe'></th></span></q></dt></tr></i><div id='flyAe'><tfoot id='flyAe'></tfoot><dl id='flyAe'><fieldset id='flyAe'></fieldset></dl></div>
                  本文介绍了如何检索给定域类的弹簧数据存储库实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  给定某个类 Bar 中所有 Spring 数据存储库的列表:

                  Given the list of all spring data repositories in some class Bar:

                  @Autowired
                  private List<Repository> repositories;
                  

                  如何在上述列表中找到现有域类 Foo 的存储库?

                  How can I find the repository for an existing domain class Foo in the above list?

                  假设存在以下情况:

                  @Entity
                  public class Foo {
                    ...
                  }
                  

                  public interface FooRepository extends JpaRepository<Foo, String> {}
                  

                  推荐答案

                  Spring Data Commons 包含一个类 Repositories,它采用 ListableBeanFactory 来查找其中定义的所有存储库 bean并公开一个 API 以按域类获取这些实例(通过 ....getRepository(Class<?> type)).

                  Spring Data Commons contains a class Repositories that takes a ListableBeanFactory to find all repository beans defined in it and exposes an API to obtain these instances by domain class (through ….getRepository(Class<?> type)).

                  应谨慎使用此类.由于存储库实例正在进行一些重要的代理生成,因此您必须确保在 ApplicationContext 创建期间尽可能晚地创建 Repositories 实例.首选方式是实现ApplicationListener并通过监听ContextRefreshedEvent来创建实例.

                  This class should be used with care. As there's some serious proxy generation going on for the repository instances you have to make sure the Repositories instance is created as late as possible during the ApplicationContext creation. The preferred way is to implement ApplicationListener and create the instance by listening to the ContextRefreshedEvent.

                  如果您正在编写 Web 应用程序,使用 Repositories 最安全的方法是在 ContextLoaderListener 创建的 ApplicationContext 中引导存储库code> 并放置 Repositories (参见 参考文档 Spring MVC 了解详情.

                  In case you're writing a web application, the safest way to use Repositories is by bootstrapping the repositories in the ApplicationContext created by the ContextLoaderListener and place the Repositories (see the reference documentation of Spring MVC for details.

                  这篇关于如何检索给定域类的弹簧数据存储库实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    <tbody id='p2InM'></tbody>
                    <legend id='p2InM'><style id='p2InM'><dir id='p2InM'><q id='p2InM'></q></dir></style></legend>

                    <small id='p2InM'></small><noframes id='p2InM'>

                        <tfoot id='p2InM'></tfoot>
                          <bdo id='p2InM'></bdo><ul id='p2InM'></ul>
                          <i id='p2InM'><tr id='p2InM'><dt id='p2InM'><q id='p2InM'><span id='p2InM'><b id='p2InM'><form id='p2InM'><ins id='p2InM'></ins><ul id='p2InM'></ul><sub id='p2InM'></sub></form><legend id='p2InM'></legend><bdo id='p2InM'><pre id='p2InM'><center id='p2InM'></center></pre></bdo></b><th id='p2InM'></th></span></q></dt></tr></i><div id='p2InM'><tfoot id='p2InM'></tfoot><dl id='p2InM'><fieldset id='p2InM'></fieldset></dl></div>