The road to java framework learning - Spring's architecture

Spring's architecture
Spring is an open source lightweight framework
Spring project development process:
create a project -> add the necessary class library jar package -> create a source file programming call library -> create a bean configuration file -> run and debug
core features
1. AOP: Aspect-oriented programming 
2. IOC: Inversion of control, the creation of objects is handed over to Spring management, dependency injection DI, and object generation is placed in XML definition
3. Across three layers of javaEE
    Web layer: SpringMVC
    Service layer: Spring IOC

    Dao layer: jdbcTemplate


As shown in the figure above, the modules of the Spring framework are divided into four categories: core container (Core Container), data access integration (DataAccess/Integration), Web (MVC/Remoting) and other modules, with a total of about 20 modules

Core container
The core container, that is, the bottom four modules in the figure, are core, bean, context and expression language modules, among which the
  core module provides the basic components of the framework, including IoC and dependency injection functions.
  The Bean module provides the BeanFactory, which is a complex implementation of the factory pattern.
  The context module builds on the solid foundation provided by the core and bean modules, and is a medium for accessing any object defined and configured. The ApplicationContext interface is the focal point of the context module.
  The Expression Language module provides a powerful expression language for querying and manipulating an object graph at runtime.
Data access/integration
The data access/integration layer includes JDBC, ORM, OXM, JMS, and transaction processing modules, of which:
  JDBC module provides a JDBC abstraction layer that removes redundant JDBC-related coding.
  The ORM module provides an integration layer for popular object-relational mapping APIs, including JPA, JDO, Hibernate and iBatis.
  The OXM module provides an abstraction layer that supports object/XML mapping implementations for JAXB, Castor, XMLBeans, JiBX and XStream.
  The Java Message Service JMS module contains functionality for producing and consuming messages.
  The transaction module supports programmatic and declarative transaction management for classes that implement special interfaces and for all POJOs.
Web
The web tier consists of Web, Web-MVC, Web-Socket and Web-Portlet, where:
  The web module provides basic web-oriented integration functionality, such as the ability to upload multiple files and the use of servlet listeners and web-application-oriented contexts to initialize the IoC container.
  The Web-MVC module contains Spring's Model-View-Controller (MVC), which implements the web application.
  The Web-Socket module provides support for WebSocket-based, and provides two ways of communicating between client and server in web applications.
  The Web-Portlet module provides the implementation of MVC in a portlet environment and mirrors the functionality of the Web-Servlet module.
Other modules
There are other important modules like AOP, Aspects, Instrumentation, Web and Test modules, among them,
  AOP module provides aspect-oriented programming implementation, allowing you to define method interceptors and pointcuts to decouple code cleanly , which implements the functionality that should be separated.
  The Aspects module provides integration with AspectJ, a powerful and mature Aspect Oriented Programming (AOP) framework.
  The Instrumentation module provides class instrumentation support and class loader implementation in certain application servers.
  The Messaging module provides support for the use of STOMP as a WebSocket subprotocol in applications. It also supports an annotation programming model for routing and processing STOMP messages from WebSocket clients.

  The test module supports testing of Spring components with JUnit or TestNG frameworks.

                                                                                                                                                              

Spring IOC container:

Divided into Spring BeanFactory container and Spring ApplicationContext container

The ApplicationContext container includes all the functionality of the BeanFactory container, so it is generally recommended to override the BeanFactory. BeanFactory can still be used for lightweight applications, such as mobile devices or applet-based applications, where its data volume and speed are significant.
The Spring IOC container is the heart of the Spring Framework. The container will create objects, wire them together, configure them, and manage their entire lifecycle from creation to destruction. The Spring container uses Dependency Injection (DI) to manage the components that make up an application. These objects are called Spring Beans
Bean container components. The core of the entire IoC container, the so-called Bean container, is where the Bean objects and various data required. Among them, BeanFactory is a pure Bean container, which is used to store and describe beans, regardless of other environments. Like ApplicationContext, it is also a Bean container, but it is closely related to the application environment, so it is more appropriate to be called application context (environment). ApplicationContext not only has beanFactory" Lineage", and also inherits EnvironmentCapable, MessageSource, ApplicationEventPublisher, which extends many of its additional functions, and its implementation class is related to the specific application of the

underlying principle of the IOC container:

(1), xml configuration file

(2), dom4j solves xml

(3), factory design mode

(4), reflection

IOC operation:
1. IOC configuration file method
2. IOC annotation method
The entire workflow:
ApplicationContext context = new ClassPathXmlApplicationContext(path);
0. Create a new ApplicationContext container object (not initialized);
1. ResourceLoader loads and parses resource files—— —> Obtain the Resource object;
2. BeanDefinitionReader reads the Resource object and encapsulates the bean element data it reads into the 
BeanDefinition component;
3. BeanDefinitionRegister registers all BeanDefinitions in the BeanFactory 
(BeanDefinition is the basic data structure of the bean inside the container, BeanFactory maintains a 
BeanDefinition Map);
4. The container initialization begins, the container initialization is completed by the 
refresh() method provided by AbstractApplicationContext, and the
context function is completed as the application environment context. After that, the program can pass the context's geBean 
(String beanName) method. Get the bean object defined by the path file declaration

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324462953&siteId=291194637