Home > Enterprise >  The role of Spring listener ContextLoaderListener
The role of Spring listener ContextLoaderListener

Time:09-19

We automatically loaded in SSH program spring configuration files need to be on the web. Add a configuration XML file:
The Xml code copy

ContextConfigLocation

The classpath * : XML applicationContext - *.





Org. Springframework. Web. Context. ContextLoaderListener




===========================================
ContextLoaderListener role is to start a Web container, automatic assembly ApplicationContext configuration information, because it implements the ServletContextListener interface, on the Web. The XML configuration the listener, start the container, will default to the method to realize it, as for the ApplicationContext. XML where the deployment configuration file, how to configure multiple XML files, how didn't elaborate on the book, now is to view its API documentation, linked in the ContextLoaderListener ContextLoader this class, so the whole loading process are done by ContextLoader configuration, see the API description



The first paragraph that can be generated by ContextLoaderListener and ContextLoaderServlet ContextLoader, if you look at the ContextLoaderServlet API, you can see it also associated ContextLoader this class and it has realized the HttpServlet, this interface

The second paragraph, ContextLoader XmlWebApplicationContext such a class is created, it implements the interface is WebApplicationContext - & gt; ConfigurableWebApplicationContext - & gt; ApplicationContext - & gt;

The BeanFactory so that all the beans in the spring from this class to create

The third section, about how to deploy the applicationContext XML files, if in the web. Don't write any parameters in the XML configuration information, the default path is "/web - INF/applicationContext. XML, XML files created in the web - INF directory name must be the applicationContext. XML, it is if the custom file name should in the web. In the XML to join this context contextConfigLocation parameter:
Xml code

ContextConfigLocation

/WEB - INF/classes/applicationContext - *. XML





In & lt; Param - value> The XML file name specified in the corresponding, if there are multiple XML files, you can write together and a ", "number space, the above applicationContext - *. XML using a wildcard, such as this has applicationContext that directory - ibatis - base. XML, applicationContext - action. XML, applicationContext - ibatis - dao. The XML file, such as can be loaded

CodePudding user response:

Configure the listener, used in the spring of defined bean class GetBean method is required to obtain, or using the object can be directly

CodePudding user response:

Xsi: schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" & gt;
4.0.0 & lt;/modelVersion>
Com. Smart
Chapter18try & lt;/artifactId>
& lt; Packaging> War
1.0.0 - SNAPSHOT
I also have this problem, is pom. The XML without plus war inside the line configuration, match well to generate the lib package, but only the project path with the target of his bag and still no tomcat directory, forced to manually copy the past, ok
  • Related