spring-Injection Object List

Source: Internet
Author: User

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 an entity bean
1. Create a package under SRC
Package Name: Cn.jbit.spring092901.domain
2. Create a bean under a package
Bean Name: Countrygeneralsituation.java
Bean content:
public class Countrygeneralsituation {
Private String countryname;//Country name
Private String womb;//Birthplace
Private String relic;//Ruins
Omit Get and set
}
Five. 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: Listfromref.java
Bean content:
public class Listfromref {
Private list<countrygeneralsituation> List;

Public list<countrygeneralsituation> getList () {
return list;
}

public void setlist (list<countrygeneralsituation> List) {
This.list = list;
}
}
3. Configure the Bean in the core configuration file
<bean id= "Listfromrefbean" class= "Cn.jbit.spring092901.collection.ListFromRef" >
<property name= "List" >
<list>
<ref bean= "Babylonbean"/>
</list>
</property>
</bean>

<bean id= "Babylonbean" class= "Cn.jbit.spring092901.domain.CountryGeneralSituation" >
<property name= "CountryName" value= "Ancient Babylon" ></property>
<property name= "Womb" value= "Al Furat watershed, Dijlah, Nahr watershed" ></property>
<property name= "relic" value= "None" ></property>
</bean>
Six. 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: Listfromreftest.java
Class content:
public class Listfromreftest {
@Test
public void Testcgs () {
Classpathxmlapplicationcontext cxac = new Classpathxmlapplicationcontext ("Classpath:applicationContext.xml");
Listfromref Lfr = (listfromref) cxac.getbean ("Listfromrefbean");
List List =lfr.getlist ();
for (Object object:list) {
Countrygeneralsituation CGS = (countrygeneralsituation) object;
System.out.println (Cgs.getcountryname ());
}
}
}

This article is from the "Yan" blog, please be sure to keep this source http://suyanzhu.blog.51cto.com/8050189/1559514

spring-Injection Object List

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.