我使用 Apache Tomcat 7,它是 ON - Spring 3,所有库都在类路径上(编译和运行时)。
这是我在 /WEB-INF/ web.xml中的 web.xml 文件:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcherServlet-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
这是我在 WEB-INF/ dispatcherServlet-context.xml中的上下文文件:
<!-- Scans within the base package of the application for @Components to configure as beans -->
<context:component-scan base-package="controllers" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
我放入浏览器时的Tomcat错误http://localhost:8080/projectname/
是:
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml];
嵌套异常是 java.io.FileNotFoundException: 无法打开 ServletContext 资源 [/WEB-INF/dispatcherServlet-servlet.xml] ecc ecc ecc
请注意,错误涉及文件dispatcherServlet-servlet.xml而不是dispatcherServlet-context.xml(我使用、创建和映射的那个)
谢谢大家!