Spring source code analysis (a) prepare articles = "basic knowledge reserves

Overall, the various parts of a, Spring Framework

 

 

 1.Spring Core Container 

Beans and Core module is a fundamental part of the frame, providing the IoC (inversion control) and dependency injection characteristics. The basic concept here is the BeanFactory, which provides for the Classical Factory pattern to eliminate the need for the program 'singletons and allows you really separated dependencies and program logic from the configuration

1.1 Core

Spring framework mainly contains basic core tools, other components to be used in the Spring class in this package, Core module is the basic core of the other components.

1.2 Beans

It includes access to the configuration files, create and manage bean as well as Inversion of Control I Dependency Injection (IoC / DI) operations related to all classes

1.3 Context

Mold is built on the basis of Core and Beans modules, Context module inherits the properties of Beans, Spring provides a number of extensions to the core, adds support for internationalization (eg resource bundles), event propagation, resource loading and transparent creation of Context support. Key Context module also supports some of the features of J2EE, ApplicationContext interface is the Context module

BeanFacotry and ApplicationContext essential difference :( BeanFacotry the bean is used to load the delay, delay ApplicationContext non-loaded)

1.4 Expression Language

Module provides a powerful expression language for querying and manipulating objects at run time. It is an extension of the JSP 2.1 unifed expression language defined in the specification. Call the language supports with straight / get property values, distribution attributes, methods for accessing the array context (accessiong the context of arrays), the container and indexers, logical and arithmetic operators, named variables and from Spring IoC container retrieving objects by name. It also supports the projector list, selection list and general polymerization

2.Spring Data Access/Integration

2.1)JDBC

Module provides a JDBC abstraction layer, it can eliminate the error code tedious JDBC coding and parsing of database-vendor specific. This module contains all classes Spring data access on JDBC encapsulated
2.2) ORM module popular object - relational mapping the API,
such as JPA, JDO, Hibernate, iBatis etc., to provide an interactive layer. Using the ORM package, it can be mixed with all the characteristics provided by the Spring O / R mapping, simple declarative transaction management feature mentioned previously.
2.3) OXM module provides an abstraction layer one pair ObjecνXML mapping implementation, Object / XML mapping implementations include JAXB, Castor, XMLBeans, JiBX and XStrearn
2.4) the JMS (the Java Messaging-Service)
module mainly contains some characteristic manufacture and consumption of messages.
2.5) Transaction
support programming and declarative transaction management, these matters must implement a specific interface, and are applicable to all POJO

 

3.Spring Web

Web module: provides a Web-oriented integration features c based e.g., file upload, initialize the IoC container using servlet listeners for a Web application and context. It also includes the relevant parts of Spring Web Remote support

4.Spring AOP

4.1) Aspects module provides integrated support for AspectJ's.
4.2) Instrumentation module provides class instrumentation support and classloader achieved, making it possible to use on a specific application server

5. Test

Test modules support the use of JUnit and TestNG test components for Spring

Two, Spring inherits FIG container

 

Which BeanFactory, ApplicationContext, ClassPathXmlApplicationContext worth focusing on

Third, the core idea is to place the IOC, not by using the resources of both the management of resources, and managed by third parties without the use of resources, which can bring many benefits.

First, centralized management of resources, resource configurable and easy to manage. Second, reducing the use of resources dependence between the two sides, that is, we say that the degree of coupling

Four, Spring IOC container bottom annotated with

1. Configure bean

The first way:

<?xml version="1.0" encoding="GBK"?>  
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns="http://www.springframework.org/schema/beans"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">  
    <!-- 指定class属性,通过构造方法创建Bean实例 -->  
    <bean id="person" class="com.mao.gouzao.Person">  
    </bean>  
</beans>  
public static void main( String[] args )
{
    ClassPathXmlApplicationContext ctx = new         
    ClassPathXmlApplicationContext("beans.xml");
    System.out.println(ctx.getBean("person"));
}    

The second way:

 

@Configuration
public class MainConfig {

    @Bean
    public Person person(){
        return new Person();
    }

}

 

Note: the form @Bean is the use of words, bean default name is the method name, if @Bean (value = "bean name") is the name of the bean specified

To read the container Bean information ( incoming class configuration )

 

public static void main( String[] args )
{
    AnnotationConfigApplicationContext ctx = new 
    AnnotationConfigApplicationContext(MainConfig.class);
    System.out.println(ctx.getBean("person"));
}

 To be continued ....

Guess you like

Origin www.cnblogs.com/chz-blogs/p/11449291.html