Home  >  Article  >  How does spring work?

How does spring work?

清浅
清浅Original
2019-03-29 17:37:4941323browse

The working principle of Spring is to allow the creation of an object to be automatically produced without using new. It can dynamically create objects and call objects with the xml Spring configuration file at runtime without the need to associate them through code.

How does spring work?

How does spring work?

[Recommended course: spring tutorial

The concept of Spring

Spring is a multi-layered J2EE application framework, the core of which is to provide a new mechanism Manage business objects and their dependencies. It is a container framework used to create beans and maintain relationships between beans. It can manage the web layer, persistence layer, business layer, etc. It can configure the components of each layer and maintain the relationship between each layer

Spring Features

(1) Lightweight: Lightweight is for heavyweight containers (EJB). Spring’s core package is less than 1M in size, and using Spring The resources required by the core package are also small, so it can be used in small devices.

(2) Non-intrusive: Spring aims to be a non-intrusive service framework. The reason is that all frameworks provide a large number of functions for users to use, thereby simplifying development time and costs. However, due to the extensive use of the framework's API, the application and the framework have a large number of dependencies and cannot be independent from the framework. , and the program components cannot be used in other programs.

(3) Container: Spring provides container functions. Containers can manage the life cycle of objects and the relationship between objects. We can set object relationships and initial values ​​by writing XML, so that after the container is started , all objects can be used directly, without writing any coding to generate objects. Spring has two different containers: Bean factory and application context

Spring working principle

The core of Spring is IOC, dynamic injection, so that an object There is no need for new to create, it can be produced automatically. This is actually using reflection in java. Reflection is actually to dynamically create and call objects at runtime. Spring uses the xml Spring configuration file to dynamically create objects at runtime. and calling methods in the object.

Another core of Spring is AOP aspect-oriented programming, which can supervise and control a certain type of object (that is, calling the module you specify before and after calling the specific method of this type of object) to achieve control. A module extends the functionality. These are achieved through configuration classes.

The purpose of Spring is to make the relationship between objects and objects (modules and modules) not related through code, but all managed through configuration class descriptions

Summary: The above is the summary of this article That’s all, I hope it’s helpful to everyone.

The above is the detailed content of How does spring work?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn