Spring入门_02_属性注入
Spring 的set方法(属性)注入
UserAction类中设置属性和get、set方法。(实际上只需要set方法)
private List list = null;
private Set set = null;
private Map map = null;
private Properties props = null;
//get、set方法省略。
applicationContext.xml
<bean id="userAction" class="com.umgsai.spring.UserAction" scope="singleton">
<property name="manager">
<ref bean="userManager">
</property>
<property name="list">
<list>
<value>123</value>
<ref local="cur">
</list>
</property>
<property name="set">
<set>
<value>Hello</value>
<value>12.36</value>
<value>124</value>
<value type="java.lang.String">true</value><!--指定type-->
</set>
</property>
<property name="map">
<map>
<entry key="a1">
<value>umgsai</value>
</entry>
<entry key="a2">
<value>umgsai2</value>
</entry>
</map>
</property>
<property name="props">
<props>
<prop key="x1">as</prop>
<prop key="x2">1265.3</prop>
</props>
</property>
</bean>
MainClass.java
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
UserAction ua = (UserAction)factory.getBean("userAction");
for(Object o : ua.getList()){
System.out.println(o);
}
for(Object o : ua.getSet()){
System.out.println(o);
}
for(Iterator iter = ua.getMap().entrySet.iterator();iter.hasNext();){
Entry entry = (Entry)iter.next();
System.out.println(entry.getKey()+":"+entry.getValue()s);
}
本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/1255528
Spring入门_02_属性注入的更多相关文章
- 这篇文章,我们来谈一谈Spring中的属性注入
本系列文章: 读源码,我们可以从第一行读起 你知道Spring是怎么解析配置类的吗? 配置类为什么要添加@Configuration注解? 谈谈Spring中的对象跟Bean,你知道Spring怎么创 ...
- Spring框架的属性注入
1. 对于类成员变量,常用的注入方式有两种 * 构造函数注入(没有空的构造方法注入) * 属性setter方法注入(有空的构造方法注入) 2. 在Spring框架中提供了前两种的属性注入的方式 1. ...
- Spring笔记②--各种属性注入
Ioc 反转控制 反转资源获取的方向 分离接口与实现 采用工厂模式 采用反转控制 Di 依赖注入 依赖容器把资源注入 配置bean 通过全类名(反射) 配置形式:基于xml方式 Ioc容器的b ...
- Spring学习笔记(二)——Spring相关配置&属性注入&Junit整合
一.Spring的相关配置 1.1 Bean元素 class属性:被管理对象的完整类名 name属性:给Bean起个名字,能重复,能使用特殊字符.后来属性 id属性:给Bean起个名字,不能重复,不能 ...
- Spring - IoC(2): 属性注入 & 构造注入
依赖注入是指程序运行过程中,如果需要另外的对象协作(访问它的属性或调用它的方法)时,无须在代码中创建被调用者,而是依赖于外部容器的注入. 属性注入(Setter Injection) 属性注入是指 I ...
- Spring为某个属性注入值或为某个方法的返回值
项目中用到需要初始化一些数据,Spring提供了filed的值注入和method的返回值注入. 一.Field值的注入 filed值注入需要使用org.springframework.beans.fa ...
- Spring中的属性注入注解
@Inject使用 JSR330规范实现的 默认按照类型注入 如果需要按照名称注入,@Inject需要和@Name一起使用 @Resource JSR250规范实现的,需要导入不同的包 @Resour ...
- Spring入门_03_构造注入
实体类 Student.java package com.umgsai.spring.entity; import java.util.Date; public class Student { pri ...
- Spring.net页面属性注入
.条件spring.web程序集 1.1 system.web配置 <httpHandlers> <add verb="*" path="*.aspx& ...
随机推荐
- 成为JavaGC专家(1)—深入浅出Java垃圾回收机制
转载自:http://www.importnew.com/1993.html 对于Java开发人员来说,了解垃圾回收机制(GC)有哪些好处呢?首先可以满足作为一名软件工程师的求知欲,其次,深入了解GC ...
- C# asp.net mvc 配置多个route 参数
mvc 中路由可以自定义 public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { ...
- asp.net mvc 缓存
webConfig 里面配置缓存时间 <caching> <outputCacheSettings> <outputCacheProfiles> <add n ...
- Python 学习笔记9(装饰器,decorator)
31 装饰器 装饰器可以对一个函数.方法或者类进行加工,是一种高级的python语法. 装饰函数 接收一个可调用对象作为输入参数,并返回一个新的可调用对象. 把函数传递给装饰器,然后增加新的功能,返回 ...
- 61.Android适配的那些P事(转)
转载:http://www.jianshu.com/p/29ef8d3cca85 首先我们看看百度搜索引擎上常见的认识入手: 图1:屏幕分辨率和常见屏幕密度关系 我们知道屏幕密度直接关系到我们所谓的1 ...
- bzoj 1257
商最多有sqrt(n)个. #include<iostream> #include<cstdio> #include<cstring> #include<al ...
- Spring mvc web 配置
Spring Framework本身没有Web功能, Spring MVC使用WebApplicationContext类扩展ApplicationContext ,使得拥有web功能.那么,Spri ...
- div内容上下居中
今天无聊闲逛技术群,听一哥们说要在div里面居中span内容. 第一印象:vertical-align: middle; 结果失效.因为他只对属于inline的元素或是inline-block.tab ...
- Beta版本——第七次冲刺博客
我说的都队 031402304 陈燊 031402342 许玲玲 031402337 胡心颖 03140241 王婷婷 031402203 陈齐民 031402209 黄伟炜 031402233 郑扬 ...
- NOIp 0916 爆零记
题目来自神犇chad 上次爆零是说着玩,这次真的爆零了QAQ 好吧貌似是TYVJ的模拟赛打多了..一直按照TYVJ的格式提交的压缩包.. 然后莫名其妙就AK了hhh 来的时候迟到了半小时,昨晚痛苦的补 ...