Spring Quick Start

Source: Internet
Author: User

What is Spring
Spring is a layered javase/ee full-stack (one-stop) lightweight open-source framework
Layered
The three-tier architecture of the EE provided by Sun: Web tier, business layer, data access layer (persistence layer/integration layer)
Struts2 is the Web layer based on the MVC design pattern Framework
Hibernate is an ORM framework for the persistence layer
One-Stop
Spring Framework has a solution for each layer on layer three
Web tier: Spring MVC
persistence layer: JDBC Template
Business layer: Spring's bean Management
the core of spring
IOC(inverse of control inversion ): Set the object's creation right to spring completion
AOP (Aspect Oriented Programming): is an object-oriented feature extension. Instead of replacing object-oriented, it is used to solve some problems in OO.
Spring Benefits
easy decoupling for simplified development
Spring is a large factory that can maintain all object creation and dependency relationships and give spring management
support for AOP programming
Spring provides aspect-oriented programming, which can easily implement the functions of permission interception, operation monitoring, etc.
support for declarative transactions
The management of transactions can be done only through configuration, without the need for manual programming
Easy testing of programs
Spring support for JUNIT4, which can be easily tested with annotations for spring programs
Easy integration of a variety of excellent frameworks
Spring does not exclude a variety of excellent open source frameworks that provide direct support for a variety of excellent frameworks (e.g. Struts, Hibernate, MyBatis, quartz, etc.)
reduce the difficulty of using Java EE APIs
Spring provides encapsulation for some of the most difficult APIs (JDBC, JavaMail, remote calls, and so on) in Java EE Development, making these API applications much less difficult to apply
Spring's Getting Started program
Download the Spring development package  
Spring-framework-3.2.0.release-dist.zip---Spring development package
docs:spring Framework APIs and specifications
libs:spring development of JAR packages
schema:xml the constraint document.
Spring-framework-3.0.2.release-dependencies.zip---A dependency package in spring development
Create a Web project to bring in the appropriate jar package  
Spring-beans-3.2.0.release.jar
Spring-context-3.2.0.release.jar
Spring-core-3.2.0.release.jar
Spring-expression-3.2.0.release.jar
development of the logging package:
Com.springsource.org.apache.commons.logging-1.1.1.jar---Packages for consolidating other logs (similar to hibernate slf4j)
Com.springsource.org.apache.log4j-1.2.15.jar
Create a spring configuration file  
Create a applicationcontext.xml under SRC
constraints introduced with XML: find xsd-config.html. Introducing Beans Constraints

<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.xsd "  >

  Writing implementation Classes

 Public class Implements  HelloService {  private  String info;   publicvoid  setInfo (String info) {  this. info = info;  }  publicvoid  SayHello () {System.out.println ("Hello Spring ..." +info); }}

  Configuring the class in Configuration

<!--sets the class's information through a <bean> tag, using the id attribute to identify the class. -<BeanID= "UserService"class= "Cn.yzu.spring3.demo1.HelloServiceImpl">    <!--using <property> Tag injection Properties -    < Propertyname= "Info"value= "Hello"/></Bean>

  To create a test class

@Test // Spring Development  Public void Demo2 () {  //  Create a factory class. New Classpathxmlapplicationcontext ("Applicationcontext.xml"= (helloservice)  Applicationcontext.getbean ("UserService"); Helloservice.sayhello ();}

IOC and DI (* * * * *) difference?
IOC: Control reversal: The creation of objects is managed by spring.
DI: Dependency Injection: In the process of creating objects in spring, the properties that are dependent on the object are injected into the class.
Spring Framework load configuration file
ApplicationContext Application Context, loading Spring Framework configuration file
load classpath:new Classpathxmlapplicationcontext ("Applicationcontext.xml");: Load classpath configuration file below
Load Disk path:new Filesystemxmlapplicationcontext ("Applicationcontext.xml");: Load disk under Configuration file
What is the difference between beanfactory and applicationcontext?
the ApplicationContext class inherits the Beanfactory
Beanfactory When using this class, the Getbean () method loads the class, and theApplicationContext class loads the configuration file, creating all the classes
ApplicationContext provides an extension to Beanfactory: International Processing, event delivery,Bean automatic assembly, and context implementations of various application tiers
early Development using beanfactory, use cases:

@Test  Public void Demo4 () {  //  classpathresource filesystemresourcenew xmlbeanfactory (  New Filesystemresource ("applicationcontext.xml"= (helloservice) beanfactory.getbean ("UserService  "); Helloservice.sayhello ();}

MyEclipse Configuring XML Hints
Window--->xml catalog--->add Locate the schema, copy the copied path to the specified location, and select schema location.

Spring Quick Start

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.