在Spring中,“类型自动装配”的意思是如果一个bean的数据类型与其它bean属性的数据类型相同,将自动兼容装配它。
例如,一个“persion” bean 公开以“ability”类数据类型作为属性,Spring会找到ability类相同的数据类型,并自动装配它的Bean。如果没有匹配找到,它什么也不做。
 
package auto_w;

/**
* Created by luozhitao on 2017/8/8.
*/
public class ablity { public void setWrite_able1(String write_able1) {
this.write_able1 = write_able1;
} public String getWrite_able1() {
return write_able1;
} private String write_able1;
}
package auto_w;

/**
* Created by luozhitao on 2017/8/8.
*/
public class Person { public void setLity(ablity lity) {
this.lity = lity;
} public ablity getLity() {
return lity;
} private ablity lity;
}
package auto_w;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Created by luozhitao on 2017/8/8.
*/
public class p_app { public static void main(String [] args){ ApplicationContext context=new ClassPathXmlApplicationContext("beans.xml"); Person person=(Person)context.getBean("person");
System.out.println(person.getLity().getWrite_able1()); }
}
 <bean id="person" class="auto_w.Person" autowire="byType"></bean>
<bean id="ablity" class="auto_w.ablity">
<property name="write_able1" value="write"/>
</bean>

Spring中类型自动装配--byType的更多相关文章

  1. Spring中的自动装配

    src\dayday\Person.java package dayday;/** * Created by I am master on 2016/11/28. */public class Per ...

  2. spring第一课,beans配置(中)——自动装配

    •Spring IOC 容器可以自动装配 Bean. 需要做的仅仅是在 <bean> 的 autowire 属性里指定自动装配的模式 •byType(根据类型自动装配): 若 IOC 容器 ...

  3. Spring 自动装配 byType

    自动装配 byType,这种模式由属性类型指定自动装配. Spring 容器看作 beans,在 XML 配置文件中 beans 的 autowire 属性设置为 byType.然后,如果它的 typ ...

  4. Spring 学习——Spring注解——Autowiring(自动装配)

    装配方式 方式一:默认 方式二:byName:根据属性名称自动装配.会查找Bean容器内部所有初始化的与属性名成相同的Bean,自动装配.(需要通过set方法注入,注入Bean的id名称需要和实体类的 ...

  5. Spring(六)之自动装配

    一.自动装配模型 下面是自动连接模式,可以用来指示Spring容器使用自动连接进行依赖注入.您可以使用元素的autowire属性为bean定义指定autowire模式. 可以使用 byType 或者  ...

  6. Spring 由构造函数自动装配

    Spring 由构造函数自动装配,这种模式与 byType 非常相似,但它应用于构造器参数. Spring 容器看作 beans,在 XML 配置文件中 beans 的 autowire 属性设置为 ...

  7. 6、Spring教程之自动装配

    自动装配说明 自动装配是使用spring满足bean依赖的一种方法 spring会在应用上下文中为某个bean寻找其依赖的bean. Spring中bean有三种装配机制,分别是: 在xml中显式配置 ...

  8. Spring autowire自动装配 ByType和ByName

    不使用自动装配前使用的是类的引用: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=& ...

  9. Spring - 配置Bean - 自动装配 关系 作用域 引用外部属性文件

    1 Autowire自动装配1.1 使用:只需在<bean>中使用autowire元素<bean id="student" class="com.kej ...

随机推荐

  1. 如何自定义echarts 线性图的选择事件

    最近在做公司的数据大盘,要用到图表显示,echarts研二的时候有用过,我就决定用它了. 这里用到一个可以同时显示多条曲线的line-charts,基本样子如下: 看到这个画红色圈圈的地方了吗??? ...

  2. quartz(6)--集群

    Quartz应用能被集群,是水平集群还是垂直集群取决于你自己的需要.集群提供以下好处: · 伸缩性 · 高可用性 · 负载均衡 目前,Quartz只能借助关系数据库和JDBC作业存储支持集群. qua ...

  3. Sqoop-将MySQL数据导入到hive orc表

    sqoop创建并导入数据到hive orc表 sqoop import \ --connect jdbc:mysql://localhost:3306/spider \ --username root ...

  4. windchill系统——开发_客户端自定义

    步骤如下

  5. zip无法解压

    使用unzip解压,提示 [root@iZ28g3behi3Z html]# unzip /var/www/html/deyizhonggong.zipArchive:  /var/www/html/ ...

  6. Json -- 语法和示例,javascript 解析Json

    1. 语法 JSON(JavaScriptObject Notation)一种简单的数据格式,比xml更轻巧.JSON是JavaScript原生格式,这意味着在JavaScript中处理JSON数据不 ...

  7. JNIjw02

    1.VC6(CPP)的DLL代码: #include<stdio.h> #include "jniZ_JNIjw02.h" JNIEXPORT void JNICALL ...

  8. The 2014 ACM-ICPC Asia Mudanjiang Regional Contest

    The 2014 ACM-ICPC Asia Mudanjiang Regional Contest A.Average Score B.Building Fire Stations C.Card G ...

  9. angular2-scroll-module

    这篇介绍一下,写一个自己的angular2滚动监听插件 目录结构: /scrollModule: ztw-scroll.module.ts; scrollBind.directive.ts; scro ...

  10. IOS-日期处理

    主要有以下类: NSDate -- 表示一个绝对的时间点NSTimeZone -- 时区信息NSLocale -- 本地化信息NSDateComponents -- 一个封装了具体年月日.时秒分.周. ...