When building the spring framework, the spring-related configuration in web.xml can be configured without ContextLoaderListener (that is, only with DispatcherServl

When building the spring framework, can the spring-related configuration in web.xml not be configured with org.springframework.web.context.ContextLoaderListener (that is, only with org.springframework.web.servlet.DispatcherServlet)?
 
 
Yes, the premise is that you do not use spring's inversion of control (ie Ioc), and use spring mvc as Struts, that is, only map the relationship between url and action.
 
 
==============Same online question and answering process============
 
 
http://bbs.csdn.net/topics/391076893?page=1
This is the case, in most of the integration of spring and springMVC on the Internet, two things need to be configured in web.xml: 

1. Configure the listener for spring, as shown in the figure:


2. Configure the servlet for springMVC, as shown in the figure:


A configuration like the above does work, I've tested it.

However, in my company, the integration of spring and springMVC is also adopted. The strange thing is that I only see the servlet configuration of springMVC in web.xml, but not the configuration of spring listener. As shown in the figure below, the company's web.xml configuration:

The number of lines in web.xml is too many to be cut, but I have searched carefully, and there is indeed no spring listener configuration!

Is it possible to cancel the listener configuration of spring after the integration of spring and springMVC?
 
 
Great answer:
1
ContextLoaderListener is to call some configuration to initialize when the context is loaded, such as tags such as <context-param> that you configure.
2
1. If there is only one Servlet of Spring mvc, the listener can be omitted.
2. But if Shiro is used, the Spring configuration used by Shiro must be loaded in the listener.
3. Generally, the Spring configuration of Dao and Service will be loaded in the listener, because it may be used in multiple servlets. Because of the visibility problem of the parent-child Context, it is loaded in the listener to prevent repeated loading.

Therefore, sometimes it can be used or not, and sometimes it must be used, depending on the situation.
3
It is estimated that your project is not used with the Ioc container.
Generally, spring listeners are configured for use with the Ioc container.

As you can see in the spring source code, when the web server is started, the context initialization method of the listener is called, and then the Ioc container is initialized.


 
http://blog.csdn.net/ideality_hunter/article/details/53318206

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326616638&siteId=291194637