spring 的默认自动装配是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9519460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 04:58:59  来源:igfitidea点击:

What is the default autowiring in spring?

springautowired

提问by M Sach

Looking at my web application, it looks like the default autowiring is by name. I did not use the autowire keyword in any XML files, but it's still autowiring. Based on this link, it looks like no autowiring should happen in this case.

查看我的 Web 应用程序,看起来默认的自动装配是按名称进行的。我没有在任何 XML 文件中使用 autowire 关键字,但它仍然是自动装配的。根据此链接,在这种情况下似乎不应发生自动装配。

Why is this happening? Can we set it at a global level somewhere in the project?

为什么会这样?我们可以在项目的某个地方将它设置为全局级别吗?

回答by Igorock

The default autowiring in spring is by type

spring 中的默认自动装配是按类型

回答by M Sach

As this linkdescribes

正如此链接所描述的

Default, no auto wiring, set it manually via “ref” attribute. In case of autodetect – If a default constructor is found, use “autowired by constructor”; Otherwise, use “autowire by type”.

默认,没有自动接线,通过“ref”属性手动设置。在自动检测的情况下 - 如果找到默认构造函数,请使用“由构造函数自动装配”;否则,请使用“按类型自动装配”。