2. Add Spring-framework-3.1.1.release Environment:
1) After extracting the downloaded spring environment, dist The following jar package into the project Lib folder.
2) Add the Applicationcontext.xml file to the project config under the following content:
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <!--3 -middle tier application context definition for the image database.4 -5 <Beansxmlns= "Http://www.springframework.org/schema/beans"6 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"7 Xmlns:context= "Http://www.springframework.org/schema/context"8 Xmlns:tx= "Http://www.springframework.org/schema/tx"9 xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdTen Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-con Text-2.5.xsd One http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd "
> A - <!--automatic scanning and assembly of beans - - <Context:component-scanBase-package= "Cn.clear.web"></Context:component-scan> the - </Beans>
3) Click on the project name right---"Build Path---" ADD Libraries---"Select JUnit---" Click Next---"Select JUnit4---" Finish. Added the JUnit environment.
4) Create the Springtest.java under Cn.clear.web.test, as follows:
1 Packagecn.clear.web.test;2 3 Importorg.junit.Test;4 ImportOrg.springframework.context.ApplicationContext;5 ImportOrg.springframework.context.support.ClassPathXmlApplicationContext;6 7 Public classSpringtest {8 9 @TestTen Public voidtestspring () { One AApplicationContext AC =NewClasspathxmlapplicationcontext ("Applicationcontext.xml"); - -Actiontest actiontest = (actiontest) ac.getbean ("Actiontest"); the System.out.println (actiontest); - } -}
5) Add annotations on the Actiontest.java class:
@Controller//Control layer annotations, adding this annotation on the class facilitates spring management for dependency injection.
A new bean instance is created @Scope ("prototype")//Every request to the bean.
6) in Springtest.java, check the method name testspring right-click on the runs---JUnit Test, if the result shows the green bar, the console output information, the spring environment adds success:
Console output: [email protected]
SSH Integration two: Adding a spring environment