Build and test the spring Development Environment
1. Import the class library
\ Dist \ spring. Jar
\ Lib \ Jakarta-commons \ commons-logging.jar
If you use aspect Programming AOP, you also need to import the following:
\ Lib \ aspectj
Aspectjrt. Jar
Aspectjweaver. Jar
If you use annotations in the jsr-250, such as @ resource/@ postconstruct/@ predestroy, you also need the following JAR files:
\ Lib \ J2EE \ common-annotations.jar
2. Beans. 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"
Xsi: schemalocation =Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<Bean
Id ="Personservice"
Class ="Cn. Kevin. Service. impl. personservicebean"> </Bean>
</Beans> |
3. personservice. Java
|
PackageCN. Kevin. Service;
Public
InterfacePersonservice {
Public
Abstract voidSave ();
} |
4. personservicebean. Java
|
PackageCN. Kevin. Service. impl;
ImportCN. Kevin. Service. personservice;
Public
ClassPersonservicebean
ImplementsPersonservice {
Public
VoidSave (){
System.Out. Println ("I am the Save method ..");
}
} |
5. Test. Java
|
@ Test
Public
VoidTest (){
Applicationcontext CTX =NewClasspathxmlapplicationcontext ("Beans. xml ");
Personservice personserivce = (personservice) CTX. getbean ("personservice ");
Personserivce. Save ();
} |