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.