The current situation is that a lot of Java programmers must be called Spring, and such a large-scale programmer collectively called "Spring", reflects the power of the Spring framework. Spring is called spring, you and I will call Spring. ^ _ ^
Spring's design is to simplify J2EE development, so if we learn, when you use it, you need to grasp the blades to spit the white foam, isn't it a joke? As far as my experience, Spring is doing well in this regard, and it is indeed a fashionable frame.
I have designed a J2EE test system, using EJB (see
http://blog.9cbs.net/brom/archive/2004/08/27/86291.aspx), I intend to use an exam system to do an example for easy comparison. The rough structure of the two systems is similar, but the new version uses a lightweight solution, using Hibernate as an ORM framework, all objects are handed over to Spring.
First, IOC and DI
First, I would like to talk about IOC (Inversion of Control, control reversal). This is the core of Spring, which is always running. The so-called IOC, for the Spring framework, is the relationship between the lifecycle and the object between the objects of the object. What does this mean, give a simple example, how do we find a girlfriend? Common situation is that we have to see where there is a beautiful figure and good mm, then inquire about their hobbies, QQ number, telephone number, IP number, IQ number ......... I want to know them, vote Send it to give it, then 嘿嘿 ... This process is complex, we must design and face each link. The traditional program development is also the same, in an object, if you want to use another object, you must get it (yourself, or query one from JNDI), you have to destroy the object after using it, such as Connection, etc.) Objects will end with other interfaces or classes.
So how is IOC do? It is a bit like a girlfriend like a marriage, introducing a third party between me and girlfriend: Marriage introduction. The marriage manages many men and women's materials, I can make a list to the marriage, tell it what kind of girlfriend, such as long as Li Jiaxin, the body like Lin Xilai, singing like Jay Chou, speed like Carlos, technology In the case of the class, then the marriage will provide a mm according to our requirements, we only need to talk to her, marry. It's simple, if the wedding is given to our candidates, we will throw an exception. The whole process is no longer controlled by my own, but a mechanism that is married such a similar container to control. This is the case, all of which will be registered in the Spring container, tell Spring what you need, what you need, then Spring will take the things you want to take the initiative to take the thing when the system is running Also give you something you need for you. All classes are created, destroyed by spring, that is, the control object's survival cycle is no longer referenced to its object, but Spring. For a specific object, it used to control other objects, and now all objects are controlled by Spring, so this is called control reversal. If you don't understand, I decided to give up.
A focus of IOC is to dynamically provide other objects they need in the system run. This is implemented by Di (Dependency Injection, dependency injection). For example, object A needs to operate the database. We always have to write code in A to get a connection object. We just need to tell Spring. A does not need to know. When the system is running, Spring creates a Connection when appropriate, and then injects it to A, which is injecting the relationship between the various objects. A Need to rely on Connection to run normally, and this connection is injected from Spring to A, depending on the name of the injected. So how is DI implement? An important feature of Java 1.3 is reflected, which allows the program to dynamically generate objects, perform objects, and change the properties of the object, and Spring is injected through reflection. Please check the Java DOC on the relevant information about reflection. After understanding the concepts of IOC and DI, everything will become simple, and the rest is just a pile of building blocks in the spring frame.
Author:
Bromon