SSH integration 2: Add a Spring environment and integrate the spring environment with ssh

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.