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

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

        @autowired on 方法在 Spring

        时间:2023-09-28

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

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

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

                  <bdo id='EYpOK'></bdo><ul id='EYpOK'></ul>
                  本文介绍了@autowired on 方法在 Spring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在学习 Spring,据我了解,当我们在具有通用名称的方法(不是 setter 方法)上使用 @annotation 时,方法的参数是自动装配的.

                  I am learning Spring, and as far as I understand, when we use @annotation on a method which has a generic name (not a setter method), then the method's arguments are autowired.

                  public class MovieRecommender {
                  
                      private MovieCatalog movieCatalog;
                  
                      private CustomerPreferenceDao customerPreferenceDao;
                  
                      @Autowired
                      public void prepare(MovieCatalog mC,
                              CustomerPreferenceDao cPD) {
                          this.movieCatalog = mC;
                          this.customerPreferenceDao = cPD;
                      }
                  
                      // ...
                  
                  }
                  

                  因此,在此处,movieCatalogcustomerPreferenceDao 字段自动使用 mCcPD 的值.我不明白的是,这与没有@autowired"的相同方法有何不同.

                  So, here, the fields movieCatalog and customerPreferenceDao are autowired with the values of mC and cPD. What I fail to understand is how is this different from the same method without the "@autowired".

                  我理解 @autowired 应用于字段名称时,但无法理解值何时显式传递给方法(setter 或任何其他方法),那么 Spring 有什么特别之处?

                  I understand @autowired when applied to a Field name, but not able to understand when the values are explicitly being passed to the method (either a setter or any other method), then what does Spring do special?

                  推荐答案

                  答案很晚,但这里是:

                  任何用 @Autowired 注释的方法都是配置方法.字段注入完成后,在 bean 实例化时调用它.方法的参数在调用时注入到方法中.

                  any method annotated with @Autowired is a config method. It is called on bean instantiation after field injection is done. The arguments of the method are injected into the method on calling.

                  这篇关于@autowired on 方法在 Spring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何标记一个方法是强制性的? 下一篇:Hibernate 验证注解 - 验证至少一个字段不为空

                  相关文章

                  最新文章

                • <tfoot id='5AqI2'></tfoot>
                      <bdo id='5AqI2'></bdo><ul id='5AqI2'></ul>

                      <small id='5AqI2'></small><noframes id='5AqI2'>

                    1. <legend id='5AqI2'><style id='5AqI2'><dir id='5AqI2'><q id='5AqI2'></q></dir></style></legend>

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