Org. springframework. Web. Context. contextloaderlistener

Source: Internet
Author: User

 

The function of contextloaderlistener is to automatically assemble the configuration information of applicationcontext when the Web container is started. Because it implements the servletcontextlistener interface, the listener is configured in Web. XML, and the implementation method is executed by default when the container is started. There is no detailed description on how to configure multiple XML files when the configuration file applicationcontext. XML is deployed. The current method is to view its API documentation. Contextloader is associated with contextloader in contextloaderlistener. Therefore, contextloader completes the configuration loading process. See its API description

The first section describes that contextloader can be generated by contextloaderlistener and contextloaderservlet. If you view the contextloaderservlet API, you can see that it is also associated with the contextloader class and it implements httpservlet. This interface

In the second section, contextloader creates a class such as xmlwebapplicationcontext, which implements the webapplicationcontext-> configurablewebapplicationcontext-> applicationcontext-> beanfactory. In this way, all beans in spring are created by this class.

Section 3 describes how to deploy the XML file of applicationcontext. no parameter configuration information is written in XML, the default path is "/WEB-INF/applicationcontext. XML, the name of the XML file created under the WEB-INF directory must be applicationcontext. XML. If you want to customize the file name, you can add the contextconfiglocation context parameter in Web. xml:

1. <context-param>
2. <param-Name> contextconfiglocation </param-Name>
3. <param-value>
4. // WEB-INF/classes/applicationcontext-*. xml
5. </param-value>
6. </context-param>

Specify the corresponding XML file name in <param-value> </param-value>. If multiple XML files exist, they can be written together and separated by a comma. The above applicationcontext-*. XML uses wildcards, such as the directory under the applicationContext-ibatis-base.xml, applicationContext-action.xml, applicationContext-ibatis-dao.xml and other files, will be loaded together.

It can be seen that the file location of applicationcontext. XML has two default implementations:

First: put it directly under the/WEB-INF, in the web. xml declare a listener,

Type 2: Put it under classpath, but in the web. add <context-param> to XML to specify your applicationcontext. XML location for Web containers to load. According to the official file provided by struts2 integrated with spring, it is written:

1. <! -- Context configuration locations for spring XML files -->
2. <context-param>
3. <param-Name> contextconfiglocation </param-Name>
4. <param-value>/WEB-INF/applicationcontext-*. XML, classpath *: applicationcontext-*. xml </param-value>
5. </context-param>

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.