我是 Spring MVC 的新手。我有一个网络应用程序。我有以下配置:
<welcome-file-list>
<welcome-file>list.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
我需要将以下行添加到 web.xml 文件吗?
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
最佳答案
是的,您需要在 web.xml
中添加 ContextLoaderListener
,
只有 如果 您想在加载应用程序时同时加载其他 Spring 上下文 xml 文件
您可以将它们指定为
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml
</param-value>
</context-param>
关于java - 在 Spring MVC 中将 ContextLoaderListener 添加到 web.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11014782/