What is control reversal? The famous saying in Hollywood is: You stay and don't change. I will look for you later. What does it mean?
Just like an emperor and Eunuch: One day the emperor wants to lucky a beautiful girl, so he told the eunuch that I want to be lucky tonight, and the Emperor will not tell the eunuch that he will go back to the palace at the time of the evening, he will only tell the eunuch which beauty he wants. Everything else will be arranged by the eunuch. At night, the emperor will go back to the palace.Naturally, there will be beautiful women in the Emperor's dragon bed, this is the control reversal, And the beauty to the Emperor's Inner Palace is injection, eunuch is the injection controller class beanfactory in the framework, responsible for finding beautiful women and sending them to the Dragon bed. The whole harem can be seen as a spring framework. Beautiful women are the JavaBean under the control of spring.
However, the traditional model is that a hungry man goes to the lady to issue a ticket, find the foreman, and help introduce a cloud, so the foreman starts to introduce Zhang Luo to him and give him a suitable one, return the lady to the foreman and come back next time. In this process, the foreman queries the context. One function of the foreman is to find the lady they want, which is the Lookup () method, the Miss directory in the foreman is JNDI // Java Naming and Directory Interface, Miss is EJB, hunger and thirst is the client, and qinglou is the EJB container.
Have you seen the difference? It is very troublesome for a hungry man to look for a young lady. Not only do he have to look for it, but he still has to give it back after use, and the Emperor turned it over, so he does not have to worry about anything and handed it over to the eunuch for handling, the control is transferred to the Eunuch's hands, rather than the emperor. If necessary, the eunuch can inject the control. Haha, this is the beauty of spring, spring also provides support for multiple mainstream frameworks and can be integrated with other open-source frameworks.