1) Tools: (1) JDK
(2) Spring.jar, Commons-logging-1.1.1.jar (because it's just a simple demo, so just use these two jar packages)
Spring.jar is a single jar package that contains a complete release module. But not including Mock.jar, Aspects.jar, Spring-portlet.jar, and Spring-hibernate2.jar.
The Commons-logging.jar package is a prerequisite package that uses spring. Log records that are used to record the activity of the program when it is run.
After importing the jar in the IDE, you can start writing tests
2) write the configuration file under SRC
The relevant documents are as follows: Spring-demo.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "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.0.xsd "> <BeanID= "Testbean"class= "Com.gdut.springdemo.Spring"> < Propertyname= "Myspring"> <value>This is my first spring!</value> </ Property> </Bean></Beans>
Test class: Spring.java
PackageCom.gdut.springdemo; Public classSpring {PrivateString myspring; Public voidShow () {System.out.println ("--message--" +getmyspring ()); } PublicString getmyspring () {returnmyspring; } Public voidsetmyspring (String myspring) { This. myspring =myspring; }}
Testspring.java
PackageCom.gdut.springdemo;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.FileSystemXmlApplicationContext; Public classtestspring { Public Static voidMain (string[] args) {ApplicationContext ctx=NewFilesystemxmlapplicationcontext ("Src/spring-demo.xml"); Spring Spring= (Spring) ctx.getbean ("Testbean"); Spring.show (); }}
Console printing:--message--this is my first spring!
Spring environment configuration under Eclipse