Hobby.java

package com.wh.bean;

public class Hobby {
private Integer id;
private String name; public Hobby() {
// TODO Auto-generated constructor stub
} public Hobby(Integer id, String name) {
super();
this.id = id;
this.name = name;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} @Override
public String toString() {
return "Hobby [id=" + id + ", name=" + name + "]";
} }

Student.java

package com.wh.bean;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.Set; public class Student {
private Integer id;
private String name;
private String[] addressArray;
private ArrayList<Hobby> hobbylist;
private Set<Hobby> hobbysSet;
private Map<String, String> map; public Student() {
System.out.println("Student被创建了!!!");
} public Student(Integer id, String name, String[] addressArray, ArrayList<Hobby> hobbylist, Set<Hobby> hobbysSet,
Map<String, String> map) {
super();
this.id = id;
this.name = name;
this.addressArray = addressArray;
this.hobbylist = hobbylist;
this.hobbysSet = hobbysSet;
this.map = map;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String[] getAddressArray() {
return addressArray;
} public void setAddressArray(String[] addressArray) {
this.addressArray = addressArray;
} public ArrayList<Hobby> getHobbylist() {
return hobbylist;
} public void setHobbylist(ArrayList<Hobby> hobbylist) {
this.hobbylist = hobbylist;
} public Set<Hobby> getHobbysSet() {
return hobbysSet;
} public void setHobbysSet(Set<Hobby> hobbysSet) {
this.hobbysSet = hobbysSet;
} public Map<String, String> getMap() {
return map;
} public void setMap(Map<String, String> map) {
this.map = map;
} @Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", addressArray=" + Arrays.toString(addressArray) + ", hobbylist=" + hobbylist
+ ", hobbysSet=" + hobbysSet + ", map=" + map + "]";
} }

applicationContext.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" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:c="http://www.springframework.org/schema/c"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"> <bean name="hobby01" class="com.wh.bean.Hobby">
<property name="id" value="1"/>
<property name="name" value="跑步"/>
</bean>
<bean name="hobby02" class="com.wh.bean.Hobby">
<property name="id" value="2"/>
<property name="name" value="游泳"/>
</bean> <bean id="student" class="com.wh.bean.Student">
<property name="id" value="001"/>
<property name="name" value="zhangsan"/>
<!-- 数组 Property下的子标签既可以是list,也可以是array -->
<property name="addressArray">
<list>
<value>广贤路</value>
<value>三丰大夏</value>
</list>
</property>
<!-- list集合 -->
<property name="hobbylist">
<list>
<ref bean="hobby01"/>
<ref bean="hobby01"/>
</list>
</property>
<!-- set集合 -->
<property name="hobbysSet">
<set>
<ref bean="hobby02"/>
<ref bean="hobby02"/>
</set>
</property>
<!-- map集合 -->
<property name="map">
<map>
<!-- <entry key="" key-ref="" value="" value-ref=""></entry> -->
<entry key="mapKey01" value="mapValue01"/>
<entry key="mapKey02" value="mapValue02"/>
<entry key="mapKey03" value="mapValue03"/>
</map>
</property>
</bean> </beans>

TestMVC.java

package com.wh.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.wh.bean.Student; public class TestMVC { @Test
public void testStudent(){
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
Student stu =(Student)ac.getBean("student");
System.out.println(stu);
}
}

  

  

  

Spring IOC set注入的更多相关文章

  1. 一篇关于spring ioc 依赖注入3种方式的文章引用

    今天看到一篇spring ioc 容器依赖注入3种方式的文章,为了方便后面的复习,在此引用别人的文章,查看请戳我.

  2. Spring IOC 依赖注入的两种方式XML和注解

    依赖注入的原理 依赖注入的方式---XML配置 依赖注入的方式---注解的方式 Spring 它的核心就是IOC和AOP.而IOC中实现Bean注入的实现方式之一就是DI(依赖注入). 一 DI的原理 ...

  3. java框架篇---spring IOC依赖注入

    spring依赖注入的方式有4种 构造方法注入 属性注入 工厂注入 注解注入 下面通过一个实例统一讲解: User.java package com.bjsxt.model; public class ...

  4. Spring IoC 依赖注入的方法大全 XML配置方式

    Spring 依赖注入 构造方法注入 ①   根据索引注入 <bean name="student" class="cn.bdqn.SpringDI.Student ...

  5. [Spring] IOC - study

    Spring IOC简单注入例子,本例子使用JUnit进行测试.Spring版本:3.2 项目结构: Spring所需引用的JAR包: Spring XML配置: springContext.xml ...

  6. 小马哥讲Spring栈核心编程思想 Spring IoC+Bean+Framework

    小马哥出手的Spring栈核心编程思想课程,可以说是非常专业和权威的Spring课程.课程主要的方向与核心是Spring Framework总览,带领同学们重新认识重新认识IoC,Spring IoC ...

  7. spring ioc三种注入方式

    spring ioc三种注入方式 IOC ,全称 (Inverse Of Control) ,中文意思为:控制反转 什么是控制反转? 控制反转是一种将组件依赖关系的创建和管理置于程序外部的技术. 由容 ...

  8. Hello Spring Framework——依赖注入(DI)与控制翻转(IoC)

    又到年关了,还有几天就是春节.趁最后还有些时间,复习一下Spring的官方文档. 写在前面的话: Spring是我首次开始尝试通过官方文档来学习的框架(以前学习Struts和Hibernate都大多是 ...

  9. Spring IOC 注入方式

    依赖注入通常有如下两种方式: ①设值注入:IOC容器使用属性的Setter方法来注入被依赖的实例. 设值注入是指IOC容器使用属性的Setter方法来注入被依赖的实例.这种注入方式简单.直观,因而在S ...

随机推荐

  1. 腾讯云:iptables基础

    iptables 基础 iptables 基本命令 任务时间:5min ~ 10min iptables 可以简单理解为 Linux 系统内核级防火墙 netfilter 的用户态客户端. Linux ...

  2. Ajax_数据格式_HTML

    [数据格式提要] 1.在服务器端Ajax是一门与语言无关的技术.在业务逻辑层使用何种服务器端语言都可以. 2.从服务器端接收数据的时候,那些数据必须以浏览器能够理解的格式来发送.服务器端的编程语言只能 ...

  3. BNUOJ 17286 Dollars

    Dollars Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 1 ...

  4. js cookies all in one

    js cookies all in one cookies // http://10.1.5.202/auto-deploy-platform/publish/index.html // 非当前 UR ...

  5. [ZJOI2009]硬币游戏

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 920  Solved: 406[Submit][Status][Discuss] Descriptio ...

  6. ubuntu 16.04网卡找不到eth0

    自15版本开始就不叫eth0.可以通过ifconfig进行查看: ifconfig -a 其中enp3s0才是网卡的名称,lo为环路. 参考: http://blog.csdn.net/christn ...

  7. 喜欢玩warcraft的ltl

    喜欢玩warcraft的ltl 时间限制:2000 ms  |  内存限制:65535 KB 难度:3 描写叙述 ltl 很喜欢玩warcraft.由于warcraft十分讲究团队总体实力,而他自己如 ...

  8. PLY格式文件具体解释

    链接:http://blog.csdn.net/szchtx/article/details/7587999 http://cdu.net.cn/3D/2014-04-23/705.html 一.PL ...

  9. LeetCode 771. Jewels and Stones (宝石与石头)

    题目标签:Hash Table 这一题很简单,题目给了两个string:J 和 S. 只要把J 里面的 char 放入HashSet,再遍历S找出有多少个石头是宝石. Java Solution: R ...

  10. android中ping命令的实现

    /** * 推断Ping 网址是否返回成功 *  * @param netAddress * @return */ public static String isPingSuccess(int pin ...