SSH Integration two: Adding a spring environment

Source: Internet
Author: User

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

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.