這裏是春天文檔如何recomends初始化的DispatcherServlet:瞭解春季分發程序Servlet初始化
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/root-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
我的問題是關於init-param
標籤中提供了一個空PARAM值。儘管將該參數定義爲context-param
,但我們仍然提供空值。因此當傳遞給servlet的init()
方法時,contextConfigLocation
應該是null
。怎麼了,請糾正我。
你可能想看看[源代碼](http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-webmvc/4.1.1.RELEASE/org/springframework /web/servlet/DispatcherServlet.java#DispatcherServlet) – TheLostMind