Spring Core Function Package Introduction
First, the composition of the Spring framework
1.1 Spring core container
The Beans: The Beans module is used by all applications and contains all classes related to accessing configuration files, creating and managing beans, and performing Inversion of Control/Depen-dency Injection (IoC/DI) operations.
Core: The Core module mainly contains the basic core tool classes of the Spring framework, and the other components of Spring are to be used in this package, and the Core module is the basic core of other components. Of course, you can also use these tool classes in your own application system.
Context : The context of Spring is the IoC container, through which the Beans in the container can be obtained. The ApplicationContext interface is the key to the Context module. The Context module is built on top of the Core and Bean modules and provides a framework-like approach to object access similar to the JNDI Registrar.
The SpEl: Expression Language module provides a powerful expression language for querying and manipulating objects at run time.
1.2 The main components of Spring
Spring AOP: Spring's facet-oriented programming, providing an implementation of AOP (facet programming).
Spring Aspects: Spring provides integration with the AspectJ framework
Spring Beans: The basic implementation of Spring IOC, including accessing configuration files, creating and managing beans, etc., all applications use.
Spring Context: Extended services on top of basic IOC functionality, in addition to support for many enterprise-class services, including mail services, task scheduling, JNDI positioning, EJB integration, remote access, caching, and support for multiple view-layer frameworks.
Spring Context Support: Extended support for Spring context for MVC.
Spring Core: Spring's core toolkit, other packages rely on this package
Spring expression: Spring expression language
Spring Instrument: Spring's proxy interface to the server
Spring Instrument Tomcat: Spring's integration of tomcat connection pools
Spring JDBC: A simple package of JDBC
Spring JMS: A simple encapsulation to simplify the use of jms APIs
Spring orm: Integrates third-party orm implementations such as hibernate, ibatis, jdo, and spruing's jpa implementations
Spring oxm: Spring's support for object/xml mapping allows you to switch back and forth between JAVA and XML
Spring test: A simple encapsulation of test frameworks such as JUNIT
Spring tx: Consistent declarative and programmatic transaction management for JDBC, Hibernate, JDO, JPA, and more.
Spring web: Contains the core classes needed for web application development when using the Spring framework, including classes that automatically load WebApplicationContext features, Struts and JSF integration classes, support classes for file uploads, Filter classes, and a large number of tool assistance classes.
Spring webmvc: Contains all classes related to the SpringMVC framework. Contains classes related to Internationalization, Labels, Themes, and View Presentation for FreeMarker, JasperReports, Tiles, Velocity, and XSLT. Of course, if your application uses a standalone MVC framework, you don't need any classes in this JAR file.
Spring webmvc portlet: Enhancements to Spring MVC
Spring websocket: Provides Socket communication, web-side push function
Second, the principle and characteristics of Spring
Spring is a comprehensive, one-stop solution for enterprise application development, spanning the presentation, business, and persistence layers. But Spring can still integrate seamlessly with other frameworks.
2.1 Spring features
Lightweight
Inversion of control
Face the slice
container
A collection of frames
2.2 IOC container implementation
BeanFactory is the infrastructure of the Spring framework, oriented to Spring itself; ApplicationContext is aimed at developers using the Spring framework, and almost all applications where we use ApplicationContext directly instead of the underlying BeanFactory.
2.2.1BeanDefinitionRegistry registry
Each node element in the Spring configuration file is represented in the Spring container by a BeanDefinition object, which describes the bean's configuration information. The BeanDefinitionRegistry interface provides a way to manually register The BeanDefinition object with the container.
2.2.2BeanFactory top-level interface
At the top of the class structure tree, its main method is getBean(String beanName), which returns beans with a specific name from the container, and the functionality of the BeanFactory is continuously expanded through other interfaces:
2.2.3ListableBeanFactory
This interface defines several methods for accessing the basic information of beans in the container, such as viewing the number of beans, obtaining the configuration name of a certain type of bean, and checking whether a bean is included in the container.
2.3 ApplicationContext is for development applications
ApplicationContext is derived from beanFactory to provide more multifaceted practical applications.
ApplicationContext inherits the HierarchicalBeanFactory and ListableBeanFactory interfaces, on this basis
, the functionality of beanFactory is also extended through several other interfaces
ClassPathXmlApplicationContext: The configuration file is loaded from the classpath by default
2. FileSystemXmlApplicationContext: Mounts configuration files from the file system by default
3. ApplicationEventPublisher: Let the container have the ability to publish application context events, including container startup events, shutdown events, and so on.
4. MessageSource: Provides i18n international message access for applications;
5. ResourcePatternResolver: All ApplicationContext implementation classes implement features similar to PathMatchingResourcePatternResolver, which can be loaded with Spring's configuration file through a prefixed Ant-style resource file path.
6. LifeCycle: This interface was added by Spring 2.0, which provides two methods, start() and stop(), which are mainly used to control asynchronous processing. When used in detail, the interface is implemented by both ApplicationContext and specific Bean, and ApplicationContext will pass the start/stop information to all beans in the container that implement the interface to achieve the purpose of managing and controlling JMX, task scheduling, and so on.
7. ConfigurableApplicationContext extends to ApplicationContext by adding two new methods: refresh() and close() to give ApplicationContext the ability to start, refresh, and close the app context. Invoking refresh() to start the app context if the app context is closed, refresh() clears the cache and reloads the configuration information in the already started state, and close() closes the app context.
Third, the Spring life cycle
Instantiation
1. Instantiate a bean, which is what we often call new.
IOC dependency injection
2. The instantiated bean is configured according to the Spring context, which is IOC injection.
setBeanName implementation
3. If the bean has implemented the BeanNameAware interface, it will call the setBeanName(String) method it implemented, and the id value of the bean in the Spring configuration file is passed here
BeanFactoryAware implementation
4. If the bean has implemented the BeanFactoryAware interface, it will call the setBeanFactory it implemented, and the setBeanFactory (BeanFactory) passes the Spring factory itself (you can get other beans in this way by configuring a normal bean in the Spring configuration file). ApplicationContextAware implementation
5. If the bean has implemented the ApplicationContextAware interface, it will be called
setApplicationContext (ApplicationContext) method, passing in the Spring context (the same way can also implement the contents of step 4, but better than 4, because ApplicationContext is a subinterface of BeanFactory, there are more implementation methods)
The postProcessBeforeInitialization interface implements -initialization preprocessing
6. If the bean is associated with the BeanPostProcessor interface, it will be called
PostProcessBeforeInitialization (Object obj, String s) method, BeanPostProcessor is often used as a change to bean content, and since this is a method that is called at the end of bean initialization, it can also be applied to memory or caching techniques.
init-method
7. If the bean has the init-method property configured in the Spring configuration file, it automatically calls the initialization method of its configuration.
postProcessAfterInitialization
8. If the bean is associated with the BeanPostProcessor interface, it will be called
PostProcessAfterInitialization(Object obj, String s) method.
9. When the bean is no longer needed, it will go through the cleanup phase, if the bean implements the DisposableBean interface, it will call the destroy() method of its implementation; destroy-method self-configuring cleanup
10. Finally, if the destroy-method property is configured in the Bean's Spring configuration, the destroy method of its configuration is automatically invoked.
The above is a common introduction to the Spring Core Function Package, please pay attention to me for more knowledge.