A famous quote from Hollywood is: Stay still, and I'll find you.
What do you mean? Like an emperor and a eunuch.
One day the emperor wanted to be lucky some beautiful woman, then said with the eunuch, tonight I want to favor beauty
The emperor often will not tell the eunuch, what time tonight will return to the palace, will return to which Zhang Dragon, he will only tell the eunuch he wants to which beauty
Everything else to the eunuch to arrange, in the evening when the emperor back to the palace, naturally there will be a beautiful woman on the Emperor's Dragon
This is the control reversal, and the beauty sent to the emperor's chambers is to inject
The eunuch is the inside of the framework of the injection controller class beanfactory, responsible for finding beauty and sent to dragon up
The whole harem can be seen as a spring frame, and beauty is the spring-controlled JavaBean.
And the traditional pattern is that a hungry man went to miss the introduction
Looking for the foreman, helping to introduce a so-called, so the foreman began to set him up
Introduce a suitable to him, after the finished, and then return the Lady to the foreman, next time to come
In this process, the foreman is the query context, a function of the foreman is to give the client to find their miss
This is the lookup () method, and the Miss list in the foreman's hands is Jndi//java naming and directory Interface
The lady is the EJB, the Hungry Man is the client, brothel is the EJB container
Do you see the difference? Hungry man to find the lady issued very troublesome, not only to find, after the use of the young lady to return
And the emperor Cool turned, nothing to tube, to the eunuch to deal with, control transferred to the eunuch hand
Instead of the emperor, if necessary, the eunuch will inject it.
See spring's wonderful, spring also provides support for multiple mainstream frameworks
can be integrated with other open source frameworks
IoC, in the vernacular, is the relationship between the container control program, rather than the traditional implementation, directly manipulated by the program code. This also
It is the concept of the so-called "inversion of Control": control is transferred from the application code to the external container, and the transfer of control is called reversal.
USB Interface Example:
Laptops and peripheral storage devices are connected via a pre-specified interface (USB), and for notebooks,
Only the user-specified data is sent to the USB interface, where the data is to be determined by the USB device that is currently plugged in. On the USB
Before the device is loaded, it is not possible for the notebook to anticipate what device the user will connect to on the USB interface, and only after the USB device
And the dependencies between them are only beginning to form.
Corresponding to the above description of the dependency injection mechanism, at runtime (System boot, USB device load) by the container (running in the Notebook
(notebook relies on USB devices for data access) into the component (Windows
File access component).
Understand:
The traditional mode is the direct call between class and class, so there is strong coupling degree, the dependencies between programs are strong, and later maintenance is more involved.
IOC, a configuration file (XML) to describe the relationship between classes and classes, managed by the container, reducing the degree of coupling between programs, the program can be modified by a simple configuration file to achieve
Programming AOP for Facets
Aspect oriented programming (aspect-oriented programming), a technique that can dynamically and uniformly add functionality to a program without modifying the source code is achieved by precompiling and running dynamic proxies.
6.2.1IOCprinciple
IoC, intuitively speaking, is the relationship between container control programs, rather than traditional implementations, directly manipulated by the program code. This is where the concept of "inversion of control" is called. Control is transferred from the application code to the external container, and the transfer of control is called inversion. The IOC has another name-"Dependency injection (Dependency injection)". It is understood from the name that the so-called dependency injection, that is, the dependencies between components is determined by the container at run time, and figuratively speaking, that is, the container dynamically injects some kind of dependency into the component.
The following is an example of a vivid image of control inversion.
For example, a girl wants to find the right boyfriend, 6-2 shows, there are 3 ways, that is, childhood, family and friends, parents arranged.
The most popular understanding of control inversion in spring