Spring Environment Construction

Source: Internet
Author: User

The first step is to create a dynamic Web project.

The second step, download the spring-related compression package, and unzip;:

spring-framework-3.0.2.release-dependencies.zip: http://yunpan.cn/ccFvNrZAMCzqj access Password 3dbf (Spring's dependency package)

spring-framework-3.0.6.release-with-docs.zip: Http://yunpan.cn/ccFviEbKbgCrV access Password b510 (Spring's base package)

Download and unzip as shown in:

The third step, to the project, the introduction of the relevant jar package;

The list of jar packages to be introduced and the directory in which they are located, as shown in:

Spring Base jar Package

Log jar Package:

Into the project's Lib directory, as shown in:

At this point, the spring environment has been built.

Write a simple test program below to verify the availability of the environment.

The first step is to create a new User.java, as shown in:

User.java in the source code, as follows:

Package Com.cvicse.utmp.user;public class User {private int id;private String name;private int age;public int getId () {RET Urn ID;} public void setId (int id) {this.id = ID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} public int getage () {return age;} public void Setage (int.) {this.age = age;} @Overridepublic String toString () {return "User [id=" + ID + ", name=" + name + ", age=" + Age + "]";}}

The second step, in the SRC directory, creates a new Spring.xml file, as shown in:

The source code in Spring.xml is as follows:

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "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-3.0.xsd "><bean id=" user "class=" Com.cvicse.utmp.user.User "><property name=" id "value=" 1 "></property><property name=" name "value= "Xiaowei" ></property><property name= "Age" value= "></property></bean></beans>"

  

The third step is to build the test class, and the test code looks like this:

Package Com.cvicse.utmp.user;import Org.springframework.context.applicationcontext;import Org.springframework.context.support.classpathxmlapplicationcontext;public class TestUser {public static void main ( String[] args) {ApplicationContext apx = new Classpathxmlapplicationcontext ("Spring.xml"); User user = (user) Apx.getbean ("User"); SYSTEM.OUT.PRINTLN (user);}}

  

Run the results as shown in:

At this point, the environment has been set up, simple test completed.

Spring Environment Construction

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.