------------I do not have him, but the hand is ripe, humble and foolish, and eager to be hungry-------------
Spring
When you mention spring, you think of the term enterprise framework
Enterprise-Class Systems:
1. Large-scale: a large number of users, data size, data many
2. Higher performance and security requirements
3. Complex business
4. Flexible strain
--------------------------------------------------------------------------------------------------------------- -----------------------------------
I think it's better to have a look at spring's position and his author.
Spring:java in the core framework, without it will not have the status of Java now, if spring hangs up, within 3-5 years Java will hang
Spring's Rod Johnson
He's Springframework founder, Interface21 CEO.
Rich background in the C + + context, rich financial industry backgrounds
1996 begins to focus on Java server-side technology
2002 wrote "Expoert ONE-ON-ONEJ2EE design and development", changing the Java World
The technical proposition is based on practicality, PhD in musicology
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Now, let's talk about spring and put two pictures.
Data/access: Data access
Web: Network
AOP: Plane-oriented programming
Instrumentatio: Inserting piles
Core Container: The kernel (the following picture has his core content, first understand this )
Test: testing, single measurement
Official website: Spring.io take the picture
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Spring's core IOC and AOP (the IOC is detailed here)
IOC: Controlled inversion: (Inverse of control)
Controlled inversion (inversion of control) is an important object-oriented programming principle to reduce the coupling problem of computer programs, and is also the core of the lightweight spring framework, beans.
Understanding one: Transferring control of a Component object (business object) from the code itself to an external container ()
Understanding two: IOC control inversion: What is said is that the control of creating an object instance is stripped from the code control to the IOC container (Spring container) control, which is actually what you control in the XML file, focusing on the principle.
AOP: Plane-oriented programming; (Aspect oritend programming)
Referring to the relationship between objects
--------------------------------------------------------------------------------------------------------------- -----------------------------------
First case:
1. Download the jar package: (I provide node)
<!--unit Testing dependent ctrl+shif+/--> <dependency> <groupId>junit</groupId> < ;artifactid>junit</artifactid> <version>4.12</version> <scope>test</scope> </dependency> <!--spring--> & Lt;dependency> <groupId>org.springframework</groupId> <artifactid>spring-beans& Lt;/artifactid> <version>4.2.0. release</version> </dependency> <dependency> <groupid>org.springframework </groupId> <artifactId>spring-context</artifactId> <version>4.2.0. Release</version> </dependency> <!--AOP uses jar--> <dependency> < groupid> org.aspectj</groupid > <artifactId> aspectjweaver</artifactid > <ve Rsion>1.8.7</version> </dependency>
2. An ordinary class
Package Cn.dawn.day01.service;/** * Created by Dawn on 2018/3/3.*/ Public classDawnservice {PrivateString Workinfo; PrivateInteger age; Public voidWork () {System. out. println ("Info"+workinfo); } @Override PublicString toString () {return "dawnservice{"+"workinfo= '"+ Workinfo +'\ ''+", age="+ Age +'}'; } PublicString Getworkinfo () {returnWorkinfo; } Public voidSetworkinfo (String workinfo) { This. Workinfo =Workinfo; } PublicInteger getage () {returnAge ; } Public voidsetage (Integer age) { This. Age =Age ; }}
3. Large configuration file
<?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.xsd "> <bean id="Service" class="Cn.dawn.day01.service.DawnService"> <property name="Workinfo"Value="The first Spring program"></property> <property name=" Age"Value=" A"></property> </bean></beans>
4. Single Measurement
Package Cn.dawn.day01;import Cn.dawn.day01.service.dawnservice;import org.junit.test;import Org.springframework.context.applicationcontext;import Org.springframework.context.support.ClassPathXmlApplicationContext;/** * Created by Dawn on 2018/3/3.*/ Public classtest20180303 {@Test/*Introductory Case*/ Public voidt01 () {ApplicationContext context=NewClasspathxmlapplicationcontext ("Applicationcontext01.xml"); Dawnservice Service= (Dawnservice) Context.getbean ("Service"); System. out. println (service); }}
In the absence of new, he got his realization.
ApplicationContext context=new classpathxmlapplicationcontext ("Applicationcontext01.xml");
If you don't understand, I'll put a picture.
See the C in front of Classpathxmlapplicationcontext? In conjunction with this, indicating that he is the applicationcontext of the implementation class, the Richter replacement, why can not use
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Do you remember the IOC I mentioned? I'm not saying that he gave control of the created object to the spring container, so when does the container create the object, is it Getbean? Still is.... (Small experiment)
In the normal class just now, add a construct, as follows
Public Dawnservice () { System. out. println ("========================dawnservice Create =======================" ); }
The single test method is as follows
@Test /* Getting Started case * /publicvoid t01 () { ApplicationContext Context=new classpathxmlapplicationcontext (" Applicationcontext01.xml"); /* Dawnservice service = (dawnservice) context.getbean ("service"); SYSTEM.OUT.PRINTLN (service); */ }
Operation Result:
The conclusion is that when the spring container is initialized, the objects in the bean are instantiated.
Concept of Ssm-spring-01:spring + introductory case