java

package cn.ioc.student;

import java.util.List;
import java.util.Map;
import java.util.Set; public class Student {
private String name;
private Address addr;
private String[] books;
private List<String> testlist;
private Map<String,String> cards;
private Set<String> games;
private String wife; public String getWife() {
return wife;
} public void setWife(String wife) {
this.wife = wife;
} public Set<String> getGames() {
return games;
} public void setGames(Set<String> games) {
this.games = games;
} public List<String> getTestlist() {
return testlist;
} public void setTestlist(List<String> testlist) {
this.testlist = testlist;
} public Map<String, String> getCards() {
return cards;
} public void setCards(Map<String, String> cards) {
this.cards = cards;
} public String[] getBooks() {
return books;
} public void setBooks(String[] books) {
this.books = books;
} //-------------------------------------------------
public Address getAddr() {
return addr;
} public void setAddr(Address addr) {
this.addr = addr;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
//show
public void show(){
System.out.print("---我叫"+name+",---我住在"+addr.getAddr()+"---我爱看的书有"); for(int i=0;i<books.length;i++){
System.out.print(books[i]+",");
}
System.out.println("---list"+testlist);
System.out.println("---map="+cards);
System.out.println("---set="+games);
System.out.println("---wife老婆=");
}
}

address.class

package cn.ioc.student;

public class Address {
private String addr; public String getAddr() {
return addr;
} public void setAddr(String addr) {
this.addr = addr;
} }

beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- ioc -->
<bean id="address" class="cn.ioc.student.Address">
<property name="addr" value="beijing"></property>
</bean>
<!-- ref引用注入 -->
<bean id="student" class="cn.ioc.student.Student">
<property name="name" value="shangren"></property>
<property name="addr" ref="address"></property>
<!-- 数组注入 -->
<property name="books">
<array>
<value>书1</value>
<value>书2</value>
<value>书3</value>
</array>
</property>
<!-- list注入 -->
<property name="testlist">
<list>
<value>排球</value>
<value>足球</value>
<value>篮球</value>
</list>
</property>
<!-- map -->
<property name="cards">
<map>
<entry key="中国银行" value="1997081100"></entry>
<entry>
<key><value>建设银行</value></key>
<value>110110110</value>
</entry>
</map>
</property>
<!-- set -->
<property name="games">
<set>
<value>dota</value>
<value>cs</value>
<value>cs</value>
</set>
</property>
<!-- 空 null -->
<property name="wife">
<null></null>
</property>
</bean>
</beans>

test.class

package cn.ioc.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import cn.ioc.student.Student; public class Test {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
Student stu = (Student) ac.getBean("student");
stu.show();
}
}

结果

spring的各种注入的更多相关文章

  1. (spring-第3回【IoC基础篇】)spring的依赖注入-属性、构造函数、工厂方法等的注入(基于XML)

    Spring要把xml配置中bean的属性实例化为具体的bean,"依赖注入"是关卡.所谓的"依赖注入",就是把应用程序对bean的属性依赖都注入到spring ...

  2. Spring的依赖注入(DI)三种方式

    Spring依赖注入(DI)的三种方式,分别为: 1.  接口注入 2.  Setter方法注入 3.  构造方法注入 下面介绍一下这三种依赖注入在Spring中是怎么样实现的. 首先我们需要以下几个 ...

  3. spring的依赖注入的最常见的两种方法

    package com.lsz.spring.action; public class User { /** * set注入 */ private String username; public vo ...

  4. 一步一步深入spring(3)--spring的依赖注入方式

    对于spring配置一个bean时,如果需要给该bean提供一些初始化参数,则需要通过依赖注入方式,所谓的依赖注入就是通过spring将bean所需要的一些参数传递到bean实例对象的过程,sprin ...

  5. Spring Ioc-依赖注入的几种方式

    一 setter方法注入 配置文件如下: <bean id="helloAction" class="org.yoo.action.SpringSetterHell ...

  6. spring的依赖注入是什么意思

    最近学习spring框架,对依赖注入有些模糊,遂上网翻阅资料,做了下列总结,原博客为CSDN 南夏的 spring的依赖注入是什么意思,侵删! Spring 能有效地组织J2EE应用各层的对象.不管是 ...

  7. 关于spring的自动注入

    关于spring的自动注入 spring里面可以设置BeanDefinition自动注入类型,默认为AUTOWIRE_NO(不进行自动注入).mybatis里面的扫描接口生成MapperFactory ...

  8. SpringBoot系列: 理解 Spring 的依赖注入(二)

    ==============================Spring 容器中 Bean 的名称==============================声明 bean 有两个方式, 一个是 @B ...

  9. SpringBoot系列: 理解 Spring 的依赖注入(一)

    ==============================Spring 的依赖注入==============================对于 Spring 程序, Spring 框架为我们提供 ...

  10. spring boot 配置注入

    spring boot配置注入有变量方式和类方式(参见:<spring boot 自定义配置属性的各种方式>),变量中又要注意静态变量的注入(参见:spring boot 给静态变量注入值 ...

随机推荐

  1. 长江存储推全新3D NAND架构 挑战三星存储

    雷帝网 乐天 8月7日报道 作为NAND行业的新晋者,长江存储科技有限责任公司(简称:长江存储)今天公开发布其突破性技术--XtackingTM.据知情人士透露,这之前存储一直都是三星的强项. 长江存 ...

  2. Clickhosue 强大的函数,argMin() 和argMax()函数

    说实话,我喜欢Clickhouse 的函数,简单操作,功能强大.今天需要给大家介绍两个函数,argMin(),argMax() 1.argMax():计算 ‘arg’ 最大值 ‘val’ 价值. 如果 ...

  3. HDU - 1253 胜利大逃亡 (搜索)

    Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0 ...

  4. 题解 AT4867 【[ABC155D] Pairs】

    题目 两次二分 首先对ans进行二分,在\([-10^{18},10^{18}]\)之间 考虑怎么check 对于每个ans,枚举每个\(a_i\),二分查找有几个\(a_j\),使得\(a_i\ti ...

  5. cms 环境搭建

    一 :安装 JDK: 1.在根目录下新建目录 JDK 2.通过 xftp 导入 jdk 压缩包到 JDK 目录中 jdk-8u144-linux-x64.tar.gz,解压 tar -zxvf jdk ...

  6. 微软2016校园招聘在线笔试之Magic Box

    题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...

  7. 这么多Linux版本,你究竟该怎么选择?

    Linux有非常多的版本,比如世面上常见的有 Ubuntu.RedHat.Fedora.Centos等等,这么多的版本我们究竟该选哪一个呢?今天我带大家对各个版本进行一下分析和比较,帮助大家来做出更好 ...

  8. SQL语言概况(4.1)

    SQL语言概况(4.1) 目录 SQL语言概况(4.1) 4.1 SQL语言概况 4.1.1 历史及标准简介 4.1.2 SQL语言定义及特点 4.1.3 使用说明 参考资料: 数据库原理及设计(第3 ...

  9. 微信小程序使用GoEasy实现websocket实时通讯

    不需要下载安装,便可以在微信好友.微信群之间快速的转发,用户只需要扫码或者在微信里点击,就可以立即运行,有着近似APP的用户体验,使得微信小程序成为全民热爱的好东西~ 同时因为微信小程序使用的是Jav ...

  10. (1)从通信中的MCS含义开始讲起

    通信中的MCS:Modulation and Coding Scheme,意思为调制编码方案/调制编码策略,其内涵可分为两个部分:Modulation  和  Coding. 在基带的信号处理流程中, ...