1. Understand what the spring framework is?
Spring is the Java EE application Framework, a lightweight IOC and AOP container framework that is primarily a lightweight container for managing the life cycle of the JavaBean, can be used alone, and can be used in combination with the Struts framework, hibernate framework, and so on.
Advantages and disadvantages of the 2.Spring framework:
Advantages:
The lightweight container frame is not intrusive
The use of IoC containers makes it easier to combine direct relationships between objects, interface-oriented programming, and reduced coupling
Aop makes it easier to expand functionality and follow the OCP development principles
Creating an object by default is singleton and does not need to be processed with singleton mode
defects: business functions rely on Spring -specific features that rely on the spring environment
3.Spring Six modules:
Key Terms:
IOC (inversion of control) inversion IOC container = beanfactory + bean.xml
Responsible for object creation inversion, in Spring, beanfacotory is The core interface of the IOC container, which is responsible for instantiating, locating, configuring objects in the application and establishing dependencies between those objects. Xmlbeanfacotory implements the beanfactory interface, which consists of the Application object and the dependencies between objects by obtaining the XML configuration file data.
DI Dependency Injection Dependency Injection ( handles object dependencies ! ) such as: Create Action need to be processed after Action Dependent Service)
There are three kinds of injection methods in spring, one is set injection, one is interface injection, the other is construction method injection.
Aop Aspect Object program is programming for facets!
AOP is the vertical programming, such as Business 1 and Business 2 need a common operation, and to each business to add the same code, rather than write over the code, let two business common use of this piece of code.
There are two ways to implement facets-oriented implementations in spring, one is dynamic proxy, one is CGLIB, thedynamic proxy must provide an interface, and the CGLIB implementation has inheritance.
4.Spring Development Steps:
1. Download the spring source code and introduce the jar file: ( after 3.0, spring source only features spring, if spring have dependencies on other packages that need to be downloaded separately )
Commons-logging-1.1.3.jar "need to download separately, spring-dependent log Packages"
Spring-beans-3.2.5.release.jar "3.2 Source: Spring Bean node Support"
Spring-context-3.2.5.release.jar "3.2 Source: Context Support"
Spring-core-3.2.5.release.jar "3.2 Source: Core function"
Spring-expression-3.2.5.release.jar "3.2 Source: Spring expression"
2. Configure Application.xml/bean.xml (name can take one of them)
The objects that need to be created are configured in the Spring container, and the corresponding namespaces and constraints can be copied in the source code!
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Beansxmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xmlns:p= "http://www.springframework.org/schema/p"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans5 http://www.springframework.org/schema/beans/spring-beans.xsd ">6 7 <!--Create a User object -8 <BeanID= "User"class= "CN.ITCAST.B_IOC." User "></Bean>9 </Beans>
3. Create an IOC container and create an object from the IOC container!
1. Create an object by using an argument-free or parametric constructor;
2. Create objects using the factory class;
5. Detailed Spring creation beans:
1 < ID= "user" class= "Cn.itcast.b_ioc_bean." User " scope=" Singleton " lazy-init=" true " init-method = "Init" Destroy-method = "Destroy" ></ Bean >
5.1. Specify whether the bean is singleton or multiple through scope:
Scope= "Singleton" single case, start-up time to create all singleton Beans
scope= "prototype" multiple cases, start time will not be created, "Every time you get an instance from a container, a new bean will be created"
When creating Dao/service, you can specify singleton, or you can specify no, the default is a singleton! You must specify when you create the action!
5.2. Deferred initialization
Lazy-init= "false" does not delay initialization
Lazy-init= "true" means: No singleton bean was created when the container was initialized;
The instance is created the first time it is fetched from the container, and if it gets again, the object that was the last created Singleton
5.3. Initialization and destruction methods
Init-method= ""
Initializes the method, executes the initialization method after the object is created; If it is a singleton, execute once; multiple executions
Destroy-method= ""
Execute when calling the Destroy method of the Classpathxmlapplicationcontext Object!
6.Bean Life cycle:
6.1. Create an IOC container object first
6.2. Create an object each time the bean is fetched from the container
6.3. After the object is created, execute the initialization method (after each object is created)
6.4. Object Creation Complete
6.5. Container destruction, execution Destroy method
SSH Learning--spring Basics