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. 【10月新版】Aspose.Pdf 10月新版V17.10发布 | 附下载

    2019独角兽企业重金招聘Python工程师标准>>> Aspose.Pdf for .NET 17.10 更新 功能和改进 核心 概述 类别 PDFNET-38067 支持DICO ...

  2. Docker 1.13.0 详细更新日志

    本文讲的是Docker 1.13.0 详细更新日志[编者的话]Docker发布1.13.0版本,此次版本更新内容较多,以下为该版本具体的变更. 构建 添加在构建时可以指定镜像用作高速缓存源的功能. 这 ...

  3. 02-线性结构3 Reversing Linked List

    02-线性结构3 Reversing Linked List   (25分) 时间限制:400ms 内存限制:64MB 代码长度限制:16kB 判题程序:系统默认 作者:陈越 单位:浙江大学 http ...

  4. Python(Redis 中 Set/Zset 类型数据和其他操作)

    1.redis 基本操作命令 Set 操作 Set 集合就是不允许重复的列表 无序集合 sadd(name,values) 给 name 对应的集合中添加 1 个或多个元素 import redis ...

  5. pycharm(破解教程)

    1.下载破解补丁 下载补丁文件 jetbrains-agent.jar  2.双击 pycharm-professional-2019.3.exe 安装 pycharm 如果你是刚下载的pycharm ...

  6. Nacos作为配置中心时,多个服务共用一个dataId的配置

    写在前面 本文是对我之前一篇文章<Spring Cloud+nacos+Feign,实现注册中心及配置中心>的补充.此文章中简单写了如何将Nacos作为配置中心.在使用配置中心时,我们会遇 ...

  7. 树形dp compare E - Cell Phone Network POJ - 3659 B - Strategic game POJ - 1463

    B - Strategic game POJ - 1463   题目大意:给你一棵树,让你放最少的东西来覆盖所有的边   这个题目之前写过,就是一个简单的树形dp的板题,因为这个每一个节点都需要挺好处 ...

  8. shell脚本传参执行spark-submit

    读取多个目录下的本地文件,多个目录通过循环遍历的方式,以参数传递: #!/bin/bash i=0while [ $i -lt 10000 ] do echo "i=$i" spa ...

  9. 《深入理解Java虚拟机》第 3 版里面到底多了哪些知识点?本文竟然得到了本书作者的认可!

    这是why的第 47 篇原创文章 荒腔走板 大家好,我是 why.老规矩,先是简短的荒腔走板聊聊生活. 上面的图是前几天拍的,那天晚上下班后,刚刚走进小区就看到了这一轮弯月和旁边那一颗特别特别亮的星星 ...

  10. BIO、NIO、AIO的形象比喻

    BIO (Blocking I/O):同步阻塞I/O模式. NIO (New I/O):同步非阻塞模式. AIO (Asynchronous I/O):异步非阻塞I/O模型. 先看阻塞和非阻塞的区别, ...