spring-注入list集合
2014-09-29 17:40
381 查看
一.创建项目
项目名称:spring092901
二.添加jar包
commons-logging.jar
junit-4.4.jar
log4j.jar
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-core-3.2.0.RELEASE.jar
spring-expression-3.2.0.RELEASE.jar
三.添加配置文件
1.在项目中创建conf目录
/conf
2.在conf目录下添加配置文件
配置文件名称: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:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
</beans>
四.创建业务bean
1.在src下创建包
包名:cn.jbit.spring092901.collection
2.在包下创建bean
bean名称:ListBean.java
bean内容:
public class ListBean {
private List list;
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
}
3.在核心配置文件中配置bean
<bean id="listbean" class="cn.jbit.spring092901.collection.ListBean">
<property name="list">
<list>
<value>西游记</value>
<value>红楼梦</value>
<value>水浒传</value>
<value>三国演义</value>
</list>
</property>
</bean>
五.测试
1.在项目中创建test目录
/test
2.在test目录下创建包
cn.jbit.spring092901.collection
3.在包下 创建测试类
类名:ListBeanTest.java
类内容:
public class ListBeanTest {
@Test
public void testListBean(){
ClassPathXmlApplicationContext cpac = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
ListBean lb = (ListBean) cpac.getBean("listbean");
List list = lb.getList();
for (Object object : list) {
System.out.println(object);
}
}
}
本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1559508
项目名称:spring092901
二.添加jar包
commons-logging.jar
junit-4.4.jar
log4j.jar
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-core-3.2.0.RELEASE.jar
spring-expression-3.2.0.RELEASE.jar
三.添加配置文件
1.在项目中创建conf目录
/conf
2.在conf目录下添加配置文件
配置文件名称: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:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
</beans>
四.创建业务bean
1.在src下创建包
包名:cn.jbit.spring092901.collection
2.在包下创建bean
bean名称:ListBean.java
bean内容:
public class ListBean {
private List list;
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
}
3.在核心配置文件中配置bean
<bean id="listbean" class="cn.jbit.spring092901.collection.ListBean">
<property name="list">
<list>
<value>西游记</value>
<value>红楼梦</value>
<value>水浒传</value>
<value>三国演义</value>
</list>
</property>
</bean>
五.测试
1.在项目中创建test目录
/test
2.在test目录下创建包
cn.jbit.spring092901.collection
3.在包下 创建测试类
类名:ListBeanTest.java
类内容:
public class ListBeanTest {
@Test
public void testListBean(){
ClassPathXmlApplicationContext cpac = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
ListBean lb = (ListBean) cpac.getBean("listbean");
List list = lb.getList();
for (Object object : list) {
System.out.println(object);
}
}
}
本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1559508
相关文章推荐
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- spring心得4--setter注入集合(set、list、map、properties等多种集合,配有案例解析)@基本装(引用)
- Spring注入集合的值List,Set,Map,Properties
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- spring心得4--setter注入集合(set、list、map、properties等多种集合,配有案例解析)@基本装
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- [原创]java WEB学习笔记98:Spring学习---Spring Bean配置及相关细节:如何在配置bean,Spring容器(BeanFactory,ApplicationContext),如何获取bean,属性赋值(属性注入,构造器注入),配置bean细节(字面值,包含特殊字符,引用bean,null值,集合属性list map propert),util 和p 命名空间
- 【spring set注入 注入集合】 使用set注入的方式注入List集合和Map集合/将一个bean注入另一个Bean
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- spring心得4--setter注入集合(set、list、map、properties等多种集合,配有案例解析)@基本装
- Spring基于xml配置文件对list、set、map集合的属性注入
- Spring注入集合
- spring注入Set,List,Properties和Map
- spring List,Set,Map,Properties,array的使用配置文件注入实例
- Spring对字段和集合的注入---依赖注入