Spring Framework has been studied two times, the first time basically forget almost, now began to review the second pass, also review almost, than before understand a lot of things, write down today, record my small results!
First, there are two important concepts in the Spring Framework: IOC and AOP, which are not explained here! The IOC is plainly used to generate objects, creating objects, and is now generally popular with annotation configurations, so, first on the implementation layer of the DAO layer if you want to configure the bean with annotations, So the first thing you need to declare in the Applicationcontext.xml file is, oh, my bean generation is not generated without tags, I use the annotation configuration to generate, that is to say, in the configuration file to declare such a sentence: <context: Annotation-config/><!--indicates that the bean--> is configured with annotations, don't worry, not finished, but also in the configuration file description, the package scan is what package, to which package the following class annotation configuration bean, so add this sentence:
<context:component-scan
Base-package= "CN.XINQUSHI.DAO.IMPL,CN.XINQUSHI.SERVICE.IMPL,CN.XINQUSHI.AOP" ></context:component-scan >
<aop:aspectj-autoproxy/>
After this writing declaration is completed, the first need to use @component to annotate the class (Generate bean) in the implementation layer of the DAO layer, in the service Layer implementation layer, you need to define the DAO layer interface variables, generate the corresponding getter and setter, The setter method is annotated with @resource (reference bean), and then similarly, annotated with @component on the service's implementation layer, defining a reference variable for the service layer interface in action. Generate the appropriate getter and setter, with @resource annotations (reference bean) above the setter method, so that the bean generation is done!
The next step is to configure DataSource and Sessionfactory, which is relatively simple; then define a bean, what bean? Hibrenatetemplate is the object of this class, because the implementation layer of the DAO layer uses the Hibrenatetemplate object as a connection to the database, and at the implementation layer of the DAO layer, generates a reference variable Hibrenatetemplate the class object. and generate the appropriate setter method, and use @resource to annotate it (an individual can simply interpret @component as defining an object, and understanding @resource as using an object). Well, this is the use of the spring IOC!!!
。。。 Spring Framework Summary (a) ...