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

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

        @Component 和 @Named 都用于同一个 bean 类

        时间:2023-09-28

          <tfoot id='aUiKd'></tfoot>
            <bdo id='aUiKd'></bdo><ul id='aUiKd'></ul>
              <tbody id='aUiKd'></tbody>
            <i id='aUiKd'><tr id='aUiKd'><dt id='aUiKd'><q id='aUiKd'><span id='aUiKd'><b id='aUiKd'><form id='aUiKd'><ins id='aUiKd'></ins><ul id='aUiKd'></ul><sub id='aUiKd'></sub></form><legend id='aUiKd'></legend><bdo id='aUiKd'><pre id='aUiKd'><center id='aUiKd'></center></pre></bdo></b><th id='aUiKd'></th></span></q></dt></tr></i><div id='aUiKd'><tfoot id='aUiKd'></tfoot><dl id='aUiKd'><fieldset id='aUiKd'></fieldset></dl></div>
              1. <small id='aUiKd'></small><noframes id='aUiKd'>

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

                  本文介绍了@Component 和 @Named 都用于同一个 bean 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 Spring 应用程序中充当 bean 的类是否同时需要 @Component@Named?

                  Does a class which will act as a bean in a Spring application require both @Component and @Named at the same time?

                  如果两者都这样使用有什么意义?

                  What is the significance if both are used so?

                  我尝试在网上搜索并查看了这些注释的标准文档,发现它们有点混乱.

                  I tried searching the net as well as saw the standard documentation of these annotations and found them a bit confusing.

                  如果 @Named 注释没有为 bean 指定任何名称,那么最终应用程序会采用哪个名称?

                  Finally which name is taken by the application if the @Named annotation does not specify any name for the bean?

                  推荐答案

                  @Component@Named 是基本上做同样事情的注解,但来自不同的 API.

                  @Component and @Named are annotations that basically do the same thing, but come from different APIs.

                  @Component 属于 Spring API.它将要自动检测为 bean 的类标记为可以选择允许您为该 bean 指定一个名称 (@Component("foo")).如果没有明确的名称规范,检测到的 bean 将获得一个从其类的名称派生的默认名称.

                  @Component belongs to Spring API. It marks class to be autodetected as a bean and optionally allows you to specify a name for that bean (@Component("foo")). Without explicit name specification detected bean will get a default name derived from the name of its class.

                  @Named 属于 javax.inject API.它将类标记为自动检测为 bean,并要求您指定名称.

                  @Named belongs to javax.inject API. It marks class to be autodetected as a bean and requires you to specify a name.

                  Spring 支持这两种 API.在同一个类中使用这两个注解是没有意义的,因为它们提供相同的功能.

                  Spring supports both these APIs. It doesn't make sense to use both annotations at the same class since they provide the same functionality.

                  另请参阅:

                  • 3.10 类路径扫描和托管组件

                  这篇关于@Component 和 @Named 都用于同一个 bean 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:@OneToOne(optional=false) 和 @JoinColumn(nullable=false) 一起 下一篇:注释 vs XML,优点和缺点

                  相关文章

                  最新文章

                      <bdo id='J7MmC'></bdo><ul id='J7MmC'></ul>

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

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