Explore Spring Technology Insider (i): Spring overview

Source: Internet
Author: User

First, what is spring?

Spring is an open source control inversion (IoC) and aspect-oriented (AOP) container framework whose main purpose is to simplify enterprise development.


Ii. inversion of Control (IoC)

Control inversion: The so-called inversion of control is that the application itself is not responsible for the creation and maintenance of dependent objects, and the creation and maintenance of dependent objects is the responsibility of the external container.

Thus control is transferred from the application to the external container, and the transfer of control is called reversal.

public class Personservicebean {//own new object private Persondao Persondao = new Persondaobean ();p ublic void Save (person pers ON) {persondao.save (person);}} public class Personservicebean {//By spring the object is injected by the Set method private Persondao Persondao;public void Save (person person) { Persondao.save (person);} public void Setpersondao (Persondao persondao) {This.persondao = Persondao;}}

Iii. Dependency Injection (DI)

Dependency Injection: The so-called dependency injection is the execution period in which dependent objects are dynamically injected into the component by an external container.

To get a better understanding of dependency injection, we'd better ask ourselves two questions:

1. Who depends on who? Why do we need to rely?

The application relies on the IOC container, of course, and the application needs an IOC container to provide the external resources required by the object.

2. Who injected it? What was injected?

Of course, an IOC container injects an object into an application, injecting the external resources (objects, resources, constant data) required by the object.


In fact, the IOC and DI are different angles of the unified concept of the narrative, relative to the IOC, ' Dependency Injection ' clearly describes the injected object depends on the IOC container configuration dependent objects.


Iv. Why to use Spring

The introduction of spring in the project brings us the following advantages:

1. Reduce the coupling between components, to achieve the decoupling between the various layers of software.

2. Be able to use the container to provide many services, such as: Transaction management Services, messaging services and so on. When we use container management transactions, developers no longer need to manually control transactions,

There is no need to deal with complex transaction propagation.

3. The container provides singleton mode support, the developer no longer need to write implementation code.

4. The container provides AOP technology, which uses it very easy to implement functions such as permission control.

5. The container provides many auxiliary classes such as JdbcTemplate, hibernatetemplate, etc., using these classes can speed up the development of the application.

6. Spring provides integrated support for the mainstream application framework, such as integrating Hibernate, JPA, struts, etc. to facilitate our development.



Five, lightweight and heavyweight

Does spring belong to a lightweight or heavyweight framework?

Dividing an application into a lightweight or heavyweight, mainly depends on how much service he uses. The more services you use, the more the container will do for ordinary Java objects,

Will inevitably affect the release time and performance of the application.

For spring containers, it provides a lot of service, but these services are not intended to be opened by the application, the application needs some kind of service, and it is necessary to indicate the use of the service, assuming that the application uses very few services,

For example, using only the spring core service, we can feel that the application is lightweight, assuming that the application uses most of the services provided by spring, then the application is heavyweight.

The EJB container is now heavyweight because it implicitly feels that the application provides all the functionality in the EJB specification.



Explore Spring Technology Insider (i): Spring overview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.