Follow new brother to learn Spring framework--Create HelloWorld project (i)

Source: Internet
Author: User

1. Introduction to Spring Framework

Spring is an open source framework, and spring is a lightweight, open source framework that was created in 2003 by Rod Johnson. The lightweight framework that primarily manages the life cycle of JavaBean, Spring brings to Java EE.

2. Spring Frame Features

lightweight : Not that his file size is very small, referring to spring is non-intrusive.
Knowledge Points: The difference between a lightweight framework and a heavyweight framework
The lightweight and heavyweight framework is determined by the resources needed to start the program, such as the need for EJB to consume a lot of resources, memory and CPU to start the program, so it is heavyweight.
Dependency Injection : IOC (DI) and plane-oriented programming: AOP
container : Spring is a container because it contains and manages the life cycle of the Application object
Framework : Spring implements a complex application that is combined with a simple component configuration.
one-stop : Integration of open source frameworks and excellent third-party libraries for enterprise applications on the basis of IOC and AOP

3. Spring Architecture

Test: Spring supports JUnit unit tests
Core Container: Inside you can see 4 core content, that is, if you need to use spring, these 4 jar packages are absolutely no less.
①spring-beans-4.3.6.release.jar (Beans): Bean factory, creating objects
②spring-core-4.3.6.release.jar (CORE): The foundation of the kernel
③spring-context-4.3.6.release.jar (context): Contextual ApplicationContext
④spring-expression-4.3.6.release.jar (el expression of spel:spring)
Knowledge Point: There is also a jar package that is necessary because spring uses it
⑤commons-logging-1.2.jar
AOP: Plane-oriented programming
Transactions: Declarative Transactions
ORM, JDBC: Can integrate hibernate and MyBatis
Web, Servlet: Can integrate STUCUS2 and spring MVC

4. Create a HelloWorld project (the most pure and simple version of the blog Park)

Download the Spring jar package: http://repo.spring.io/release/org/springframework/spring

To better understand spring's jar-pack dependencies, we don't need maven to create them. We also do not use the Web. xml file to initialize the loading spring container, completely original build. The main purpose is to understand what the purest and simplest spring projects look like.

①, first create the introduction jar package, the above 5 jar package enters can

Did you see it? A 5 jar can be created. is the smallest basic unit for creating HelloWorld. Less can not run.

②, create a Helloworld.class

1  Public classHelloWorld {2     PrivateString name;3      Public voidsetName (String name) {4System.out.println ("Set property called");5          This. Name =name;6     }7      PublicHelloWorld () {8System.out.println ("Initialize constructor");9     }Ten      Public voidHello () { OneSystem.out.println ("Hello:" +name); A     } -}

③ Create a spring configuration file Applicationcontext.xml

1 class= "HelloWorld" >2     <property name= "name" value= "Spring" ></property>3 </bean>

④ Creating a Main.class (main function entry)

1  Public Static voidMain (string[] args) {2         //1. Creating objects for the spring IOC container3ApplicationContext CTX =NewClasspathxmlapplicationcontext ("Applicationcontext.xml");4         //2. Get an instance of the bean from the IOC container5HelloWorld HelloWorld = (HelloWorld) ctx.getbean ("HelloWorld");6         //3,calling the Hello method7 Helloworld.hello ();8}

Output Result:
  Initialize the constructor
  Set properties are called
  Hello:spring


think about it, if the method in main above I commented out the instance that gets the bean and calls the Hello method (that is, 2 and 3 are all commented out), then what should the result be?
Output Result:
  Initialize the constructor
  Set properties are called

It is explained that when the SPRINGIOC container is created, the class is instantiated and the property is assigned a value

---------------------------------------------------------------------------------

Follow new brother to learn Spring frame series:Follow the new brother to learn Spring framework--Create HelloWorld project (i) follow the new brother to learn Spring Framework--spring container (ii) Follow the new brother, learn the spring framework--Configure the Bean with XML (iii) follow the new brother. Learn the Spring framework-Configure the Bean with annotations ( Four) follow the new Brother study Spring Framework--AOP (v)

Follow new brother to learn Spring framework--Create HelloWorld project (i)

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.