Spring, Spring MVC, and the IOC reading

Source: Internet
Author: User
Tags tutorialspoint

Spring vs SPRING-MVC
    • Spring is the application-level framework
    • Spring MVC is just an MVC framework
    • Spring now contains many sub-modules, and the most we use is dependency injection.
    • The spring module can be divided into the following:
      • Core Container:
      • Data access/integration:
      • Web:
      • Other, such as AOP, aspects, test, etc.:
    • The Spring module framework is as follows:
Advantages of using the spring framework
    • Develop enterprise applications like the Pojo class
    • Modular Management
    • Integrates multiple technologies such as ORM, logging, Quartz, JDK timers, etc.
    • Easy to test
Disadvantages of using the spring framework
    • First, the software system due to the introduction of the third-party IOC container, the process of generating objects has become somewhat complex, it is a matter between the two, and more out of thin air-formalities, so, when we first use the IOC framework, we will feel the system becomes less intuitive.
    • Second, because the IOC container generates objects through reflection, there is a certain loss in operational efficiency. If you want to pursue operational efficiency, you have to weigh it, such as WEB2.0.
    • Third, specific to the IOC framework products (such as: Spring), the need for a lot of preparation work, more cumbersome, for some small projects, the objective may also increase some of the cost of work
    • Iv. the maturity of the IOC framework product itself needs to be evaluated, and if an immature IOC framework product is introduced, it will affect the entire project, so this is also an implicit risk.
Spring IoC

1. Two types of containers:
    • Spring beanfactory Container
    • Spring ApplicationContext Container
      ApplicationContext container contains all the functions of beanfactory container, the first push ApplicationContext container in enterprise application;
      But in lightweight applications such as mobile devices and applet applets, Beanfactory still comes in handy.
2.Metadata Configuration
    • XML based configuration file
    • annotation-based Configuration
    • java-based Configuration
Spring IOC Container action

The idea presented by IOC theory is broadly true: the decoupling of objects with dependencies is achieved by means of "third parties".
Due to the introduction of the intermediate position of the "third party", that is, the IOC container, so that a, B, C, D these 4 objects do not have a coupling relationship, the transmission between the gears all rely on "third party", all the control of the object to the "third party" IOC container, so, the IOC container becomes the key core It acts like an "adhesive" that binds all objects in the system together, and if there is no "binder", the objects and objects will lose touch with each other, which is the origin of the IOC container being likened to an "adhesive".


Figure 1: Coupling objects in a software system


Figure 3:IOC Decoupling process


Figure 4: System after taking out the IOC container

The origin of the IOC name

What exactly is the name of the inversion of control (IOC)? Let's compare:

Before the introduction of the IOC container, the software system 1 shows that object a relies on object B, so when object a initializes or runs to a certain point, it must take the initiative to create object B or Use object B that has already been created. Whether you are creating or using object B, you have control over your own hands.

After the introduction of the IOC container, the software system completely changed, 3, as the IOC container joins, object A and object B lose direct contact, so when object a runs to object B, the IOC container will actively create an object B to inject to object a where it is needed.

Through the contrast, we do not look ugly: object A to rely on the process of object B, from the active behavior to passive behavior, control reversed, this is the name of "control reversal" the origin.

IOC aliases: Dependency Injection (DI)

In 2004, Martin Fowler explored the same issue, since the IOC was a reversal of control, so "what controls are reversed?" After detailed analysis and argument, he came to the answer: "The process of acquiring dependent objects has been reversed." After control is reversed, the process of acquiring a dependent object is managed by itself into an active injection by the IOC container. So he gave the "inversion of control" a more appropriate name called "Dependency Injection (Dependency injection)". His answer, in effect, gives a way to implement the IOC: inject. The so-called dependency injection is that the IOC container dynamically injects some kind of dependency into the object during operation.

Therefore, Dependency injection (DI) and inversion of control (IOC) are the same thing that is described from different angles, that is, by introducing an IOC container, the decoupling of objects is realized by means of dependency injection.

Resources

"1" Spring Quick Guide
Http://www.tutorialspoint.com/spring/spring_quick_guide.htm
The IOC principle of "2" spring
Http://www.importnew.com/14751.html
"3" Spring MVC Framework Build-page at the end of the detailed build process link
Http://www.tutorialspoint.com/spring/spring_web_mvc_framework.htm



From for notes (Wiz)

Spring, Spring MVC, and the IOC reading

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.