SSH integration 2: Add a Spring environment and integrate the spring environment with ssh
2. Add spring-framework-3.1.1.RELEASE environment:
1) decompress the downloaded spring environment and copy the jar package under dist to the project lib folder.
2) Add the applicationContext. xml file to the project config. The content is as follows:
1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <! -- 3-Middle tier application context definition for the image database. 4 --> 5 <beans xmlns = "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.springfra Mework.org/schema/beans/spring-beans-2.5.xsd10 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd11 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd "> 12 13 <! -- Automatically scans and assembles beans --> 14 <context: component-scan base-package = "cn. clear. web "> </context: component-scan> 15 16 </beans>
3) Right-click the project name and choose "Build Path ---" Add Libraries --- "select" JUnit --- "click" Next --- "and select" JUnit4 --- "Finish. Added the JUnit environment.
4) Create SpringTest. java under cn. clear. web. test as follows:
1 package cn.clear.web.test; 2 3 import org.junit.Test; 4 import org.springframework.context.ApplicationContext; 5 import org.springframework.context.support.ClassPathXmlApplicationContext; 6 7 public class SpringTest { 8 9 @Test10 public void testSpring(){11 12 ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");13 14 ActionTest actionTest = (ActionTest) ac.getBean("actionTest");15 System.out.println(actionTest);16 }17 }
5) add an annotation to the ActionTest. java class:
@ Controller // control layer annotation. Add this annotation to the class to facilitate spring management for dependency injection.
@ Scope ("prototype") // a new bean instance is created every time a bean is requested.
6) in SpringTest. java, right-click the method testSpring and choose Runs --- "JUnit Test. If the result shows green bars and console output information, the Spring environment is added successfully:
Console output: cn. clear. web. test. ActionTest @ 27b4c1d7