Create applicationcontext from a Web application

Source: Internet
Author: User
Create applicationcontext from a Web application

Unlike beanfactory, which is always created programmatically, applicationcontext can beContextloaderIs created in declarative form. Of course, you can also use any of the applicationcontext implementations to create it programmatically. First, let's take a look at contextloader and its implementation.

Contextloader has two implementations:ContextloaderlistenerAndContextloaderservlet. Both of them have the same functions, except that listener cannot be used in servlet 2.2 compatible containers. Since the servelt 2.4 specification, listener is required to be initialized after the web application is started. Many 2.3 compatible containers have implemented this feature. Which one to use depends on yourself, but if all the conditions are the same, you will probably preferContextloaderlistenerFor more information about compatibility, seeContextloaderservlet.

You can useContextloaderlistenerRegister an applicationcontext:

 
   
   
     contextconfiglocation 
    
   
    /WEB-INF/daocontext. XML/WEB-INF/applicationcontext. XML 
    
   
  
    Org. springframework. web. context. contextloaderlistener 
    
   
  
    context 
   
  
    Org. springframework. web. context. contextloaderservlet 
   
  
    1 
    --> 

This listener needs to check the contextconfiglocation parameter. If it does not exist, it uses /WEB-INF/applicationcontext. xml by default. If it exists , it uses a pre-defined separator (comma, semicolon, and space) split the string separately and use these values as the location to be searched by the application context. Contextloaderservlet can be used to replace contextloaderlistener. This servlet uses the contextconfiglocation parameter like listener.

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.