spring1:spring Introduction, Environment Construction and source code download

Source: Internet
Author: User

Framework Learning Preface

This module is for the Java framework of learning, mainly spring, Hibernate, Ibatis, framework of learning I think so:

1, simple introduction of the framework, mainly from the Internet for reference some key

2, as far as possible to clarify the use of the framework and details of the point

3. Try to understand some of the source code in spring with your own understanding

What is Spring?

Spring is a lightweight Java framework created to address the complexities of enterprise application development. One of the main advantages of the framework is its layered architecture, which allows the user to choose which component, while providing an integrated framework for Java EE application development. From the standpoint of simplicity, testability, and loose coupling, any Java application can benefit from spring, with the core of spring being control reversal IOC and aspect- oriented AOP.

Features of Spring

1. Light weight

Spring is lightweight both in terms of size and overhead. The full spring framework can be published in a jar file with a size of more than 1M, and the processing overhead required by spring is negligible. In addition, spring is non-intrusive: Typically, objects in spring applications do not depend on a particular class of spring.

2. Control reversal

Spring facilitates low coupling through a technique called inversion of the IOC. When an IOC is applied, other objects that an object relies on are passed in passively, rather than the object itself creating or locating dependent objects.

3. Face-Tangent

Spring provides rich support for aspect-oriented programming, allowing for the development of cohesive applications by separating the business logic of the application from the system-level services. The application only implements what they should do----complete the business logic, which is not responsible (or even unaware) of other system-level concerns, such as log or thing support.

4. Container

Spring contains and manages the configuration and lifecycle of application objects, in this sense it is a container where you can configure how each of your beans is created----based on a configurable prototype, Your bean can create a separate instance or generate a new instance each time it is needed----and how they relate to each other.

5. Framework

Spring can configure and combine simple components into complex applications. In spring, application objects are combined declaratively, typically in an XML file. Spring also provides a number of basic functions (transaction management, persistence framework integration, etc.), leaving the development of application logic to developers.

All of these features of spring enable developers to write cleaner, more manageable, easier-to-test code, and they also provide basic support for the various modules in spring.

Features of Spring

1, easy to decouple, simplify the development

With the IOC container provided by spring, we can control the dependencies between objects by spring, avoiding the over-coupling caused by hard coding. With spring, users no longer have to write code for these very low-level requirements, such as single-instance pattern classes, attribute file parsing, and can focus more on upper-tier applications.

2, AOP programming support

The AOP functionality provided by spring facilitates aspect-oriented programming, and many features that are not easily implemented with traditional OOP can be easily coped with by AOP.

3. Support of declarative Things

In spring, we can get out of the tedious transaction management code and make the management of things with declarative flexibility to improve the efficiency and quality of development.

4, convenient integration of a variety of excellent framework

Spring does not exclude a variety of excellent open source frameworks, instead, spring can reduce the difficulty of using various frameworks, and spring provides direct support for a variety of excellent frameworks such as structs, Hibernate, Hessian, quartz, and more.

5. Reduce the difficulty of using Java EE API

Spring provides a thin layer of packaging for many of the hard-to-use Java EE APIs, such as JDBC, JavaMail, RMI, and so on, and these Java EE APIs are much less difficult to use with spring's simple encapsulation

6, Java source code is a classic learning paradigm

Spring's source code design is exquisite, the structure is clear, the originality, everywhere manifests the Java design pattern flexible use as well as the advanced accomplishment to the Java technology. Spring Framework source code is undoubtedly a best practice example of Java technology, if you want to quickly improve their Java technical level and application development level in a short time, learn and study spring source code will benefit you.

Spring download

Spring-related information can be viewed on the spring website, but they are all in English.

Spring is currently the latest version is 4.2.2, click on the link to download, after the decompression should be like this:

Explain each folder:

1, under Docs is spring related materials, including an official English version of the information "Spring-framework-reference.pdf" and the web version of the spring API, which has all the spring class and method-related information, and the JDK API-Like

2. Libs includes all spring jar packages, note that "*.javadoc.jar" and "*.sources.jar" end up with some of the auxiliary documentation provided by spring for each module, not the contents of the jar package that is actually used

3, the schema is spring each component, each version of the. xsd file used to set the. xml file for automatic prompting

Spring environment setup and automatic prompt setting for. xml files

For later learning, here's how to build a spring framework and how to set up an automatic prompt for an. xml file:

1, right-click Project->build path->configure Build Path ..., choose Add External JARs ..., import all the Libs under the JAR package (if only with the function of the Bean factory is not all imported also line)

2, we know that the use of spring is written by the configuration file, so right-src->new->file, casually named, the end of XML can be

3, the XML file is written inside, this is the most basic template, all the functions in the future are expanded on this template:

 <?  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-4.2.xsd " >  </ beans  >  

4. Click Window->preferences->myeclipse->files and Editors->xml->xml catalog->add->file System ..., Select the extracted directory Schema folder, beans directory under the spring-beans-4.2.xsd, in fact, choose any version of the. XSD can, as long as your spring's. xml file in the same version number corresponding to it.

5, Key type select "Schema location", Key Fill "http://www.springframework.org/schema/beans/spring-beans-4.2.xsd", That's the path inside the. xml file.

6, click OK, then configure spring other functions such as AOP, context, JDBC What XML hints can also be used in a similar way. XML is configured with an address, and an XML catalog is added to the XML catalog Entry

Spring Log System Setup

Spring uses Apache common_logging, and with Apache log4j as the log output component, in order to be able to observe spring's log output during debugging, download the common_logging and log4j two jar packages first. I do not know the latest two jar package is what version, I use the older, previously downloaded:

After downloading, make sure that you have these two jar packages under your classpath. With these two jar packages, right-click SRC, create a new "log4j.properties" file, configured as follows:

Log4j.rootlogger=debug, stdoutlog4j.appender.stdout= org.apache.log4j.consoleappenderlog4j.appender.stdout.layout= Org.apache.log4j.patternlayoutlog4j.appender.stdout.layout.conversionpattern=%c{1}-%m%n

So, in the process of using spring, you can see the log output of spring.

Spring source download and import MyEclipse

Since we want to learn the source code, it is bound to get the source of spring. Spring source code is managed via GitHub, and downloading spring source and importing MyEclipse requires two tools:

1, GitHub, point me

2, Gradle, point me, note download installed Gradle to create Gradle_home system variables, and this system variable if to the path, and the same as the JDK, this will not be able to check the Internet, after installation into CMD, input command "gradle-version ", printing out Gradle version information means that Gradle can use the

When both GitHub and Gradle are installed, they are divided into two steps:

1. Use github to download the source code

First download and install the two tools, OK, after the GitHub bin directory double-click "Tclsh85.exe", as with the use of CMD, just find a directory you want to download, using "Git clone git://github.com/ Springsource/spring-framwwork.git "Download Spring source code,

Download complete should be:

2, the current download of the source code can not be directly imported into the MyEclipse, we also need to convert the source code to myeclipse understanding of the form, so this time will be used gradle. cmd into the rice window, switch to download the spring source of the directory, we want to put which module of the source to the MyEclipse to operate which folder, the specific way:

The conversion should be complete:

Now let's look at the Spring-beans directory under the folder:

This is the form MyEclipse know, direct import into the myeclipse, but look at it seems to be wrong:

It doesn't matter, the same amount of way to turn the Spring-core the import source project is good.

spring1:spring Introduction, Environment Construction and source code download

Related Article

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.