Download, configuration, and HelloWorld of the "Spring" Spring3.0.5

Source: Internet
Author: User

Spring this thing actually did not imagine so difficult, just because most of the information on the Internet is a mixture of many other strange technology, what maven,log4j, what things come, but also come up SSH integration, that is called beginners, how can you read? Here's a simple, no-no-additional technique to explain spring.


One, Spring download

First, spring's download is a problem. The official website of these frames has been changed, and then the new technology has been strongly pushed, and the historical version has been removed. Just like ExtJS, we can only search the historical version of the Internet in China. To make a Spring3.0 to the next two compressed packets. One is spring-framework-3.0.5.release-with-docs.zip and the other is spring-framework-3.0.5.release-dependencies.zip.

Thanks here, two csdn netizens selfless offer.

spring-framework-3.0.5.release-with-docs.zip:http://download.csdn.net/download/hl518_818/4796207

spring-framework-3.0.5.release-dependencies.zip:http://download.csdn.net/download/u014175572/7514027


Second, the spring configuration

Spring is also very egg-sore when configured. After extracting Spring-framework-3.0.5.release-with-docs.zip and Spring-framework-3.0.5.release-dependencies.zip, some books say spring-framework -3.0.5.release-with-docs.zip\ The contents of dist are copied into the content of the spring-framework-3.0.5.release-dependencies.zip and then added to your Java or Javaweb project, and finally you will find that your Java or javaweb The process cannot be run. This is because in the spring-framework-3.0.5.release\dist, more than one should not exist LIBD file.


So the right thing to do is, after eclipse creates a new Java project, here's an example of Java engineering, because spring actually doesn't have anything to do with Javaweb, just to use Java for Javaweb engineering!

After eclipse creates a new Java project named Springhelloworld, create a new Lib folder, and after extracting it, Put everything in spring-framework-3.0.5.release-dependencies with all the jar packages in spring-framework-3.0.5.release\dist, not including that libd file, Copy to the Lib folder under Java project, after doing well, your Lib folder should look like this:


After that, right-click the Java project named Springhelloworld, select Properties, then select the Add Jars package, select the jar package that you just copied to the Lib folder, and select "OK", as follows:


At this point, the spring configuration is complete.


Iii. the HelloWorld of spring

1, first in the SRC directly create a new Java file containing the main function Springtest.java, the code below.

Import Org.springframework.context.*;import org.springframework.context.support.*;p ublic class SpringTest {public static void Main (string[] args) {//Initialize Springapplicationcontext applicationcontext=new classpathxmlapplicationcontext ("Applicationcontext.xml");//inject A.java for this Springtest.java class, A A=applicationcontext.getbean ("Ajava", A.class);// After injection you can use the Class A a.print ();}}
2, after the new A.java in the SRC, the code below, simple can not be simpler, but here must strictly according to the provisions of spring, variables must be private, there must be a setter method.

public class A {private String a;public void SetA (String A) {this.a = A;} public void print () {System.out.println ("Applicationcontent.xml passes in a value of:" + A);}}
3, finally also in the SRC new applicationcontext.xml, inside the code is as follows:

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://www.springframework.org/schema/beans" xsi:schemalocation= "http://www.springframework.org/schema/ Beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd "><bean id=" AJava "class=" A ">< Property Name= "A" value= "hehe"/></bean></beans>
4, after the completion, the Java project directory should be as follows:


Back to Springtest.java run directly, the results are as follows, where the heap of log4j warns him not to ignore him, and spring does not need to rely on log4j to run. You'll have to use it again later.



Iv. Summary

So what is the above program doing?

Its variable is passed as follows, may be a bit chaotic, we make a look!


In fact, without spring, in Springtest.java, directly using a a=new a ("hehe"), and then A.java write a good construction method, can achieve the effect as above. Even if A.java is in another package, you can also use import to introduce A.java. It's just a design pattern. It is said that in the Javaweb can make the project more clear, really is "hehe".

Spring actually replaces the original Java impor role.

Download, configuration, and HelloWorld of the "Spring" Spring3.0.5

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.