I. Creating a Project
Project Name: spring092902
Two. Add a jar Package
1. Create a Lib directory in your project
/lib
2. Add the jar package in the Lib directory
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
<?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:context= "Http://www.springframework.org/schema/context"
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
Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd " >
<!--parsing Annotations--
<context:annotation-config/>
<!--scanning Notes--
<context:component-scan base-package= "Cn.jbit.spring092902.service" ></context:component-scan>
</beans>
Four. Create a bean
1. Create the package in the SRC directory
Cn.jbit.spring092902.service
2. Create a bean under a package
Bean Name: Helloservice.java
Bean content:
@Component ("HelloService")
public class HelloService {
public void SayHello () {
System.out.println ("Hello");
}
}
Five. Testing
1. Create the test catalog in the project
/test
2. Create a package in the test directory
Cn.jbit.spring092902.service
3. Create a test class under a package
Test class Name: Hellpservicetest.java
Test the contents of the class:
public class Hellpservicetest {
@Test
public void Testsayhello () {
ApplicationContext con = new Classpathxmlapplicationcontext ("Classpath:applicationContext.xml");
HelloService HelloService = (helloservice) con.getbean ("HelloService");
Helloservice.sayhello ();
}
}
This article is from the "Yan" blog, please be sure to keep this source http://suyanzhu.blog.51cto.com/8050189/1559504
Getting Started with spring-annotation implementation