Understanding of the IOC container

Source: Internet
Author: User

These two days to see spring about the IOC container chapter content, after reading the head is almost mess, many professional nouns do not know what meaning, after the end I still do not understand what is the IOC control inversion and Dependency injection! Although I combined my company's project to look at the spring configuration, and to set up the spring framework error also solved, but I still do not understand, what is the IOC control inversion, what is dependency injection?

Then I found some information on the Internet, the general meaning I was to understand the 70%, now write down their understanding of the two, if there is updated understanding, will continue to update this blog post.

IOC control inversion: In the original caller to invoke an object, the caller needs to create an object for the callee, and then after using spring, the caller does not need to be called to create objects, all of which are given to spring, this is the IOC control inversion.

Dependency Injection: What is dependency? Spring's understanding of dependency is the latter relationship, such as a call B, then A has a dependency on B. What is injection? For example, I use @repository to set a Userdao as a bean, and when I need to invoke it in another class, I need to @autowire to the bean container to find the Userdao type of bean, and if found, inject it directly into the calling class. The callee is automatically injected into it; Let me take a look at the following example:

The old age, when the woodcutter needed an axe, needed to build an axe himself. This is equivalent to the fact that we need to create an object to use when we want to invoke a class.

In modern times, when the woodcutter needed an axe, he needed to go to a special factory to pick the axe he wanted, and he didn't have to do it himself, and a factory agent created an axe for it. This is the factory model,

Now, when the woodcutter needs an axe, he just needs to sit at home and tell people that I need an axe, I can have an axe directly, I don't have to go to the factory to pick it, that's the whole meaning of the IOC container. When the caller needs an object, only one annotation is needed to get the object it needs, and spring goes directly to the bean container and finds the object for it, allowing them to establish a connection.

I understand that basically, there should be a misunderstanding of the place, in the future I have more understanding, will revise the blog post.

Understanding of the IOC container

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.