Getting Started with spring (1)---start Spring tour

Source: Internet
Author: User

Spring is an open source control reversal (inversion of controls, IoC) and a container framework for aspect-oriented (AOP). Its main aim is to simplify enterprise development.

IOC control reversal

public class Personservicebean {
     private Persondao Persondao = new Persondaobean ();
     
      public void save [person person] {
            persondao.save (person);
     }

Persondaobean is created and maintained within the application. The so-called control reversal is that the application itself is not responsible for the creation and maintenance of dependent objects, and the creation and maintenance of dependent objects are handled by the external container. Thus the control is transferred from the application to the external container, and the transfer of control is the so-called reversal.

Dependency Injection (Dependency injection)

When we give the dependent object to the external container to create it, the Personservicebean class can be changed as follows:

public class Personservicebean {
     private Persondao Persondao;
    By using the constructor parameters, the container injects the created dependent object into the Personservicebean, and of course it can be injected with the setter method. Public
     Personservicebean (Persondao persondao) {
         This.persondao=persondao;
     } 
      public void save [person person] {
            persondao.save (person);
     }

Dependency injection means that, at runtime, a dependent object is dynamically injected into an assembly by an external container.

Why do I use spring

At least in my opinion, introducing spring into a project can immediately bring the following benefits

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

You can use many of the services provided by the container, such as transaction management services, messaging services, and so on. When we use containers to manage transactions, developers no longer need to manually control transactions. Nor does it need to handle complex transactional propagation.

The container provides a single case pattern support, and developers no longer need to write the implementation code themselves.

The container provides AOP technology, it is easy to implement such functions as permission interception, runtime monitoring and so on.

The numerous auxiliary classes provided by the container, using these classes can accelerate the development of applications, such as: JdbcTemplate, Hibernatetemplate.

Spring provides integrated support for the mainstream application framework, such as integrated hibernate, JPA, struts, and so on, which makes it easier to develop applications.

If we use spring, we no longer need to manually control the transaction

Also, if you are using spring, we do not need to deal with complex transactional propagation behavior

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.