注入类:

 package helloworld;

 import java.util.List;
import java.util.Map;
import java.util.Properties; public class User {
private List list;
private Map<String, String> map;
private Properties pro; public void setList(List list) {
this.list = list;
} public void setMap(Map<String, String> map) {
this.map = map;
} public void setPro(Properties pro) {
this.pro = pro;
} public void say() {
System.out.println(list);
System.out.println(map);
System.out.println(pro);
}
}

beans.xml配置

 <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:contexnt="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <bean id="user" class="helloworld.User">
<property name="list">
<list>
<value>aaa</value>
<value>bbb</value>
<value>ccc</value>
</list>
</property>
<property name="map">
<map>
<entry key="a" value="apple"></entry>
<entry key="b" value="banner"></entry>
</map>
</property>
<property name="pro">
<props>
<prop key="name">Tom</prop>
<prop key="age">25</prop>
</props>
</property>
</bean>

测试代码:

         ApplicationContext context =  new ClassPathXmlApplicationContext("beans.xml");
// 参数注入
User user = (User) context.getBean("user");
user.say();

Spring之注入复杂类型属性的更多相关文章

  1. Spring根据XML配置文件注入对象类型属性

    这里有dao.service和Servlet三个地方 通过配过文件xml生成对象,并注入对象类型的属性,降低耦合 dao文件代码: package com.swift; public class Da ...

  2. Spring_day01--注入对象类型属性(重点)_P名称空间注入_注入复杂类型属性_IOC和DI区别_Spring整合web项目原理

    注入对象类型属性(重点) Action要new一个service对象,Service中又要new一个Dao对象,现在把new的过程交给spring来操作 1 创建service类和dao类 (1)在s ...

  3. IoC容器-Bean管理XML方式(注入集合类型属性)

    Ico操作Bean管理(xml注入集合属性) 1,注入数组类型属性 2,注入List集合类型属性 3,注入Map集合类型属性 (1)创建类,定义数组.list.map.set类型属性,生成对应set方 ...

  4. Java框架spring 学习笔记(八):注入对象类型属性

    使用set方法注入对象属性 编写UserDao.java文件 package com.example.spring; public class UserDao { public void print( ...

  5. spring学习——注入静态对象属性

    spring注入静态对象属性时,因为虚拟机类加载问题,直接在属性上使用@Autowired 是不可以的.需要在属性对应的set方法上@Autowired,并且,set方法不能定义为static. 1. ...

  6. Spring框架xml配置文件 复杂类型属性注入——数组 list map properties DI dependency injection 依赖注入——属性值的注入依赖于建立的对象(堆空间)

    Person类中的各种属性写法如下: package com.swift.person; import java.util.Arrays; import java.util.List; import ...

  7. Spring学习日记02_IOC_属性注入_其他类型属性

    ICO操作Bean管理(xml注入其它类型属性) 字面量 null值 <property name="address"> <null></null&g ...

  8. Spring学习日记03_IOC_属性注入_集合类型属性

    Ioc操作Bean管理(xml注入集合属性) 注入数组类型属性 注入List集合类型属性 注入Map集合类型属性 Stu类 public class Stu { //1. 数组类型属性 private ...

  9. spring注入对象类型的属性

    一.1.创建service类和Dao类 (1)在service中得到dao对象 2.具体实现过程 (1)在service里边把dao作为类型属性 (2)生成dao类型属性的set方法 public c ...

随机推荐

  1. 本地模拟服务器CDN(静态HTML,CSS,JS)开发

    本地模拟服务器CDN(静态HTML,CSS,JS)开发 所谓本地开发环境就是和线上cdn(a.longencdn.cn)一样的目录结构和功能,提供了一个本地镜像,开发者直接在本地镜像的对应目录中作开发 ...

  2. 优化ansible速度

    1.开启SSH长连接 ssh_args = -C -o ControlMaster=auto -o ControlPersist=1d \\连接保持一天 2.开启pipelining ansible执 ...

  3. 使用参数化查询防止SQL注入漏洞(转)

    SQL注入的原理 以往在Web应用程序访问数据库时一般是采取拼接字符串的形式,比如登录的时候就是根据用户名和密码去查询: string sql * FROM [User] WHERE UserName ...

  4. 备忘:BLOCK CORRUPTION IN SYSTEM DATAFILE

    http://www.onlinedbasupport.com/2010/12/10/block-corruption-in-system-datafile/

  5. [CTSC2006]歌唱王国

    [CTSC2006]歌唱王国 Tags:题解 题意 链接:在空串后不断随机添加字符,直到出现串\(S_i\)为止.求最终串的期望长度.\(\sum |S_i|\le 5*10^6\) 题解 以下内容来 ...

  6. helloworld讲解cocos2d-x的编程思路与要点

    用helloworld讲解cocos2d-x的编程思路与要点 本文以cocos2d-x的helloworld为例,讲解cocos2d-x引擎的特点和要点,2.2为了展示新功能,把包括屏幕自适应在内的新 ...

  7. Android Studio Xposed模块编写(二)

    阅读本文前,假设读者已经看过Android Studio Xposed模块编写(一)  相关环境已经搭建完成.本文演示案例与上文环境一致,不在赘述. 1.概述 Xposed是非常牛叉的一款hook框架 ...

  8. setBit testBit权限管理

    1.jdk7文档解释 public boolean testBit(int n) Returns true if and only if the designated bit is set. (Com ...

  9. Jq_打印

     利用IE自带的WebBrowser进行打印  打印判断: if(factory.object)//打印设置的判断 factory.printing.PageSetup(); else alert(& ...

  10. 前端菜鸟起飞之学会ps切图

    由于之前只顾着追求效率,没有学习过PS,但其实这是前端开发人员需要学会的技能之一,曾经看过一个大佬的前端经验分享说他在招聘时遇到不会切图的会直接pass掉,可见前端开发人员学会切图是多么重要.通过观看 ...