I. Creating a Project
Project Name: spring092901
Two. Add a jar Package
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
Three. Add a configuration file
1. Create the Conf directory in your project
/conf
2. Add a configuration file under the Conf directory
Configuration file name: Applicationcontext.xml
Configuration file Contents:
<?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>
Four. Create a business bean
1. Create a package under SRC
Package Name: Cn.jbit.spring092901.collection
2. Create a bean under a package
Bean Name: Setbean.java
Bean content:
public class Setbean {
Private set set;
Public Set Getset () {
return set;
}
public void Setset (set set) {
This.set = set;
}
}
3. Configure the Bean in the core configuration file
<bean id= "Setbean" class= "Cn.jbit.spring092901.collection.SetBean" >
<property name= "Set" >
<set>
<value> Analects </value>
<value> University </value>
<value> Mencius </value>
<value> Moderation </value>
</set>
</property>
</bean>
Five. Testing
1. Create the test catalog in the project
/test
2. Create a package in the test directory
Cn.jbit.spring092901.collection
3. Create a test class under a package
Class Name: Setbeantest.java
Class content:
public class Setbeantest {
@Test
public void Testlistbean () {
Classpathxmlapplicationcontext CPAC = new Classpathxmlapplicationcontext ("Classpath:applicationContext.xml");
Setbean Setbean = (Setbean) cpac.getbean ("Setbean");
Set set = Setbean.getset ();
Iterator it = Set.iterator ();
while (It.hasnext ()) {
String str = (string) it.next ();
System.out.println (str);
}
}
}
This article is from the "Yan" blog, please be sure to keep this source http://suyanzhu.blog.51cto.com/8050189/1559512
spring-Injection Set Set