注入类:

 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. jsp运算符

    一.执行运算: 支持四则运算.关系(>;<....),逻辑运算(&&.||) 注意: +:只能进行加法运算,字符串形式的数字可以进行加法运算,这里的+号不能进行字符串的拼接 ...

  2. kubernetes 资源请求和限制

    1. spec:      containers:        - name: example          resources:            requests:            ...

  3. DB2 substr,instr使用

    看示例,查询下一年'2xxx',例如今年2014,结果为2015 select substr(char(current timestamp),1,4)+1 from SYSIBM.SYSDUMMY1; ...

  4. DOTNET Core 命令

    dotnet 命令目录: 1.dotnet-new 2.dotnet-restore 3.dotnet-build 4.dotnet-run 5.dotnet-test 6.dotnet-pack 7 ...

  5. 解决php的交互式命令行不能正常启动的问题兼介绍psysh

    今天在自己的mac电脑上试着启动php的交互式命令行,发现敲下命令后一直卡在提示进入的地方,但没有出现已经进入的提示符,百度了下应该是与readline有关. 于是安装php的readline扩展,在 ...

  6. python基础学习1-流程控制和判断

    python for循环和 if流程控制用法 Ages=22 for i in range(10): inputAges = int(input("输入年龄")) if input ...

  7. AT24C02跨页写数据

    AT24C02 EEPROM的写数据分为:字节写数据模式和页写数据模式:字节写就是一个地址一个数据的写,页写是连续写数据,一个地址多个数据的写,但是页写不能自动跨页,如果超出一页长度,超出的数据会覆盖 ...

  8. maven核心,pom.xml详解

    什么是pom?    pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的u ...

  9. LeetCode 3Sum (Two pointers)

    题意 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all ...

  10. 开发工具之Spark程序开发详解

    一  使用IDEA开发Spark程序 1.打开IDEA的官网地址,地址如下:http://www.jetbrains.com/idea/ 2.点击DOWNLOAD,按照自己的需求下载安装,我们用免费版 ...