1. <legend id='ylXBN'><style id='ylXBN'><dir id='ylXBN'><q id='ylXBN'></q></dir></style></legend><tfoot id='ylXBN'></tfoot>
        <bdo id='ylXBN'></bdo><ul id='ylXBN'></ul>
    2. <small id='ylXBN'></small><noframes id='ylXBN'>

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

        将 Spring 依赖注入到 JPA 实体侦听器中

        时间:2024-08-24

        <tfoot id='HRW1e'></tfoot>
          • <bdo id='HRW1e'></bdo><ul id='HRW1e'></ul>

                <tbody id='HRW1e'></tbody>

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

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

                  本文介绍了将 Spring 依赖注入到 JPA 实体侦听器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要将 Spring 依赖项注入到 JPA 实体侦听器中.我知道我可以使用 @Configurable 和 Spring 的 AspectJ weaver 作为 javaagent 来解决这个问题,但这似乎是一个 hacky 解决方案.还有其他方法可以完成我想做的事情吗?

                  I need to have a Spring dependency injected into a JPA entity listener. I know I can solve this using @Configurable and Spring's AspectJ weaver as javaagent, but this seems like a hacky solution. Is there any other way to accomplish what I'm trying to do?

                  推荐答案

                  另一个技巧是使用静态方法实现一个实用程序类,它可以帮助您在任何地方使用 Spring bean,而不仅仅是在托管类中:

                  Another trick is to implement an utility class with static method that helps you to use Spring beans everywhere, not only in managed classes:

                  @Component
                  public final class BeanUtil {
                  
                      private static ApplicationContext context;
                  
                      private BeanUtil(ApplicationContext context) {
                          BeanUtil.context = context;
                      }
                  
                      public static <T> T getBean(Class<T> clazz) throws BeansException {
                  
                          Assert.state(context != null, "Spring context in the BeanUtil is not been initialized yet!");
                          return context.getBean(clazz);
                      }
                  }
                  

                  这篇关于将 Spring 依赖注入到 JPA 实体侦听器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Spring Data JPA 中是否有任何最简单的方法来获取表元数据(列名列表)信息?我可以在通用数据库上使用哪个 下一篇:如何在没有@Id的情况下使用spring Repository?

                  相关文章

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

                2. <legend id='36LrM'><style id='36LrM'><dir id='36LrM'><q id='36LrM'></q></dir></style></legend>

                  1. <tfoot id='36LrM'></tfoot>
                      • <bdo id='36LrM'></bdo><ul id='36LrM'></ul>

                      <small id='36LrM'></small><noframes id='36LrM'>