A preliminary understanding of the Java Framework Spring's dependency injection

Source: Internet
Author: User

The Java framework of spring as the leader of the entire project, can effectively manage the objects of each layer, effective coordinated operation, when the system of Western medicine reconstruction, can greatly reduce the amount of rewriting code.

Dependency injection and control inversion belong to the same concept, in Java, when a class (caller) needs the assistance of another class (callee), in the previous program design concept, the caller class is usually created as an instance of the Callee class (new one Callee Class). This approach to new objects typically creates a space in Java space, which can have an impact on the overall efficiency of the Java project and is a more rude approach. In the spring framework, however, the task of creating the calling class is no longer done by the caller class but by the framework (that is, the instantiated control is changed by the programmer to the container of spring), and the phenomenon becomes a control reversal (that is, reversing some of the previous ways of working). The instantiation of the caller class is usually done by the spring container, which is then injected into the caller, which is called dependency injection.

In the usual way, each invocation of the callee class requires instantiating a callee class, and if there are many classes that need to invoke the callee class, instantiate many of the callee classes. Now the spring framework assumes the middle side and prepares the callee class, who needs the callee class and the callee class is injected into the caller.

A preliminary understanding of the Java Framework Spring's dependency injection

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.