Spring--spring Getting Started

Source: Internet
Author: User
Tags log4j

Overview of spring-what is spring
    • · Spring is an open source framework
    • · Spring is designed to simplify enterprise-class application development. With spring, you can make simple
    • JavaBean implementation of functions previously only available to EJBS
    • · Spring is a one-stop frame for javase/ee
Overview of spring-what is spring
    • • 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 conveniently 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
Spring's Overview-spring benefits
    • • Easy Program Testing
    • -spring to JUNIT4 support, you can easily test the spring program with annotations
    • • Easy integration 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, etc.)
    • • Reduce the difficulty of using JAVAEEAPI
    • -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 overview of the-spring module

The underlying implementation of Spring's IOC

An introductory case for the spring IOC
    • Create a new MAVEN project using idea
    • adding dependencies in Pom.xml
<Dependencies>  <Dependency>    <groupId>Junit</groupId>    <Artifactid>Junit</Artifactid>    <version>4.11</version>    <Scope>Test</Scope>  </Dependency>  <Dependency>    <groupId>Org.springframework</groupId>    <Artifactid>Spring-core</Artifactid>    <version>4.3.7.RELEASE</version>  </Dependency>  <Dependency>    <groupId>Org.springframework</groupId>    <Artifactid>Spring-context</Artifactid>    <version>4.3.7.RELEASE</version>  </Dependency>  <Dependency>    <groupId>Org.springframework</groupId>    <Artifactid>Spring-beans</Artifactid>      <version>4.3.7.RELEASE</version>  </Dependency>    <Dependency>        <groupId>Org.springframework</groupId>        <Artifactid>Spring-expression</Artifactid>      <version>4.3.7.RELEASE</version>    </Dependency>  <Dependency>    <groupId>Commons-logging</groupId>    <Artifactid>Commons-logging</Artifactid>    <version>1.2</version>  </Dependency>  <Dependency>    <groupId>Log4j</groupId>    <Artifactid>Log4j</Artifactid>    <version>1.2.17</version>  </Dependency></Dependencies>
    • Build a Package

UserService

 Public Interface UserService {    publicvoid  SayHello ();}

  Userserviceimpl

 Public classUserserviceimplImplementsuserservice{ PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }    //Add Property    PrivateString name; @Override Public voidSayHello () {System.out.print ("Hello Spring" +name); }}

  SpringDemo1

 Public classSpringDemo1 {@Test/*** Traditional Way development*/     Public voiddemo1 () {//UserService userservice = new Userserviceimpl ();Userserviceimpl UserService =NewUserserviceimpl (); //setting properties Traditional methods It's not good to change the code.Userservice.setname ("Zhang San");    Userservice.sayhello (); } @Test/*** Use the Spring method*/     Public voidDemo2 () {//Create a spring factoryApplicationContext ApplicationContext =NewClasspathxmlapplicationcontext ("Applicationcontext.xml"); //obtaining classes through the factoryUserService UserService = (userservice) applicationcontext.getbean ("UserService");    Userservice.sayhello (); }}

Applicationcontext.xml

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "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" >    <!--the creation of the UserService is given to spring -    <BeanID= "UserService"class= "Com.windbag.ioc.demo1.UserServiceImpl">        <!--Setting Properties -        < Propertyname= "Name"value= "John Doe"></ Property>    </Bean></Beans>
    • Test

Quick Start case for Spring IOC
    • · The concept of the IOC inverse of control inversion is the control of manually creating UserService objects in the program, which is managed by the spring framework
    • • Simply put, the creation of the UserService object control is reversed to the spring frame
    • · The concept of DI Dependency injection Dependency Injection is to inject the properties that this object relies on in the process of creating this object in spring. (name)

Getting started with spring--spring

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.