1. Download spring-Related Development Kits
: Http://sourceforge.net/project/showfiles.php? Group_id = 73357
Spring-framework-1.2.6-with-dependencies.zip. one example is spring-framework-1.2.6.zip. It is recommended to download with-dependencies. There are additional packages in it. After downloading and decompressing, THE Dist directory is the jar of spring and the lib directory is.
2. Create a Java project and add spring. Jar (under the DIST directory) and commons-logging.jar (under the lib directory) to the build path of the project.
3. Create a pojo Bean class: hellobean
// Hellobean. Java
/**
*
*/
Package com. lzy;
/**
* @ Author lzy
*
*/
Public class hellobean {
Private string hello;
Public void sayhello (){
System. Out. println (this. gethello ());
}
/**
* @ Return returns the hello.
*/
Public String gethello (){
Return hello;
}
/**
* @ Param Hello the hello to set.
*/
Public void sethello (string Hello ){
This. Hello = Hello;
}
}
4. Create the bean. xml file and assign a value to the hello attribute of a hellobean instance in this XML file.
// Bean. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype beans public "-// spring // DTD bean // en" "http://www.springframework.org/dtd/spring-beans.dtd">
<Beans>
<Description> spring Quick Start </description>
<Bean id = "hellobean" class = "com. lzy. hellobean">
<Property name = "hello">
<Value> Hello World </value>
</Property>
</Bean>
</Beans>
5. Create a test class: testspring
// Testspring. Java
/**
*
*/
Package com. lzy;
Import java. util. locale;
Import org. springframework. Context. applicationcontext;
Import org. springframework. Context. Support. filesystemxmlapplicationcontext;
/**
* @ Author lzy
*
*/
Public class testspring {
/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
Applicationcontext CTX = new filesystemxmlapplicationcontext ("bean. xml ");
Hellobean Hello = (hellobean) CTX. getbean ("hellobean ");
Hello. sayhello ();
}
}
6. Run the test class:
If no error occurs, "Hello World" will be displayed in the output ".