Description of the "important" Spring configuration principle in Web. xml

Source: Internet
Author: User
Tags connection pooling

Spring Principle Description:

//Mode 0: Change in the implementation class, with which to change which
//New out, the coupling is too strong, depending on the specific implementation class, if my specific implementation of the class changed, then the interface code here also has to change, so bad.
//private Iuserdao DAO = new Iuserdaoimpl ();
//private Iuserdao DAO = new Iuserdaoimplfororacle ();


//Mode one: Do not modify in the implementation class, change the parameters of forname in the factory class
//private Iuserdao DAO = Beanfactory.newinstance (). Getuserdao ();

//Mode two: not modified in the factory class, modified in the configuration file, get the normal object, is my own to generate
//private Iuserdao DAO = (Iuserdao) beanfactory.newinstance (). Getdao ("Userdao");
//Private Iuserdao DAO1 = (Istudentdao) beanfactory.newinstance (). Getdao ("STUDENT");

//Way three: Not in the factory class modification, modify in the configuration file, get the proxy object, let proxy object help me to generate, I go this is the most lazy way ah!
private Iuserdao dao = (Iuserdao) beanfactory.newinstance (). Getproxydao ("Userdao");

//each time you want to use this proxy class object, each time will be generated, but Iuserdao object, I only need to getxxx () generated once is enough, and later is called inside the method, and there is no assignment operation.
//Recall Why we use database connection pooling? A : because the connection to the database is the most time consuming, namely getconnection.
//We use the database connection pool to put this most time-consuming operation at the very beginning, when the server starts, because when the server starts, everyone is waiting.

///Similarly, when the server starts, can we put the operations of the generated proxy objects somewhere and let them wait? A : of course I can! We can put them in a global domain (a map).
//Why is it "put"? Answer: There is no assignment operation because there is only a fetch operation.
//How to do it? Answer: initialize a container (a map container).
//How do I know you started it? When do you initialize a container? Answer: use server listener.
///Servletcontextlistener, this listener listens to the creation and destruction of the application domain because the application is loaded as soon as the server is started. The listener can hear it.

//What is spring doing? A : when the server starts, you initialize a container such that all the proxy objects you want to use are thrown inside, and if you want to use them, remove them from the inside.
// so spring in Web. XML is configured to implement a listener that implements the Servletcontextlistener interface.

The knowledge in the following picture is very important, it is very helpful to understand the spring principle, please download to watch:

Description of the "important" Spring configuration principle in Web. xml

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.