Spring Autowiring by AutoDetect
In Spring, “Autowiring by AutoDetect“, means chooses “autowire by constructor” if default constructor (argument with any data type), otherwise uses “autowire by type“.
See an example of Spring “auto wiring by autodetect”. Auto wiring the “kungfu” bean into “panda”, via constructor or type (base on the implementation of panda bean).
<bean id="panda" class="com.mkyong.common.Panda" autowire="autodetect" />
<bean id="kungfu" class="com.mkyong.common.KungFu" >
<property name="name" value="Shao lin" />
</bean>
1. AutoDetect – by Constructor
If a default constructor is supplied, auto detect will chooses wire by constructor.
package com.mkyong.common;
public class Panda {
private KungFu kungfu;
public Panda(KungFu kungfu) {
System.out.println("autowiring by constructor");
this.kungfu = kungfu;
}
public KungFu getKungfu() {
return kungfu;
}
public void setKungfu(KungFu kungfu) {
System.out.println("autowiring by type");
this.kungfu = kungfu;
}
//...
}
Output
autowiring by constructor
Person [kungfu=Language [name=Shao lin]]
2. AutoDetect – by Type
If a default constructor is not found, auto detect will chooses wire by type.
package com.mkyong.common;
public class Panda {
private KungFu kungfu;
public KungFu getKungfu() {
return kungfu;
}
public void setKungfu(KungFu kungfu) {
System.out.println("autowiring by type");
this.kungfu = kungfu;
}
//...
}
Output
autowiring by type
Person [kungfu=Language [name=Shao lin]]
Spring Autowiring by AutoDetect的更多相关文章
- Spring Auto-Wiring Beans
In Spring framework, you can wire beans automatically with auto-wiring feature. To enable it, just d ...
- Spring Auto-Wiring Beans with @Autowired annotation
In last Spring auto-wiring in XML example, it will autowired the matched property of any bean in cur ...
- Spring Autowiring by Constructor
In Spring, "Autowiring by Constructor" is actually autowiring by Type in constructor argum ...
- Spring Autowiring by Name
In Spring, "Autowiring by Name" means, if the name of a bean is same as the name of other ...
- Spring Autowiring by Type
In Spring, "Autowiring by Type" means, if data type of a bean is compatible with the data ...
- Spring Autowiring @Qualifier example
In Spring, @Qualifier means, which bean is qualify to autowired on a field. See following scenario : ...
- [转载]Spring Beans Auto-Wiring
Autowiring Modes You have learnt how to declare beans using the <bean> element and inject < ...
- Spring 学习——Spring注解——Autowiring(自动装配)
装配方式 方式一:默认 方式二:byName:根据属性名称自动装配.会查找Bean容器内部所有初始化的与属性名成相同的Bean,自动装配.(需要通过set方法注入,注入Bean的id名称需要和实体类的 ...
- Spring 自动装配 Bean
Spring3系列8- Spring 自动装配 Bean 1. Auto-Wiring ‘no’ 2. Auto-Wiring ‘byName’ 3. Auto-Wiri ...
随机推荐
- oracle .bash_profile
[oracle@redhat4 ~]$ vi .bash_profile # .bash_profile # Get the aliases and functionsif [ -f ~/.bashr ...
- BCB遍历所有窗体的组件
for(iFormIdx=0; iFormIdx<Screen->FormCount; iFormIdx++) { TForm *pForm = Screen->Forms[iFor ...
- poj 1054 The Troublesome Frog (暴力搜索 + 剪枝优化)
题目链接 看到分类里是dp,结果想了半天,也没想出来,搜了一下题解,全是暴力! 不过剪枝很重要,下面我的代码 266ms. 题意: 在一个矩阵方格里面,青蛙在里面跳,但是青蛙每一步都是等长的跳, 从一 ...
- 苹果官方 Crash文件分析方法 (iOS系统Crash文件分析方法)
对于提交的苹果官方的app,在审核的时候会给我们一些crash文件,对于这些有用的文件,里面是关于我们的bug的一些信息,那么该如何去调试呢 第一步:在任意目录创建一个目录,用来调试crash,我这里 ...
- 【C#学习笔记】自我复制
using System; using System.IO; using System.Diagnostics; namespace ConsoleApplication { class Progra ...
- (转)HTTP协议详解
引言 HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1. ...
- LeetCode:Sort List
Title: Sort a linked list in O(n log n) time using constant space complexity. 思路:考虑快速排序和归并排序,但是我的快速排 ...
- 【DFS/BFS】NYOJ-58-最少步数(迷宫最短路径问题)
[题目链接:NYOJ-58] 经典的搜索问题,想必这题用广搜的会比较多,所以我首先使的也是广搜,但其实深搜同样也是可以的. 不考虑剪枝的话,两种方法实践消耗相同,但是深搜相比广搜内存低一点. 我想,因 ...
- date.plugin.js 日期插件
//定义命名空间 var DatePlugin; if (!DatePlugin) DatePlugin = {}; /*整理时间:2015-05-28*/ var defaultFormat = & ...
- sharepoint2010 创建自定义列表
转:http://boke.25k5.com/kan77298.html 如何创建自定义列表 首先了解创建自定义列表中涉及到的几个名词:栏.内容类型. ①栏:栏即列.字段(Field),MSDN中给出 ...