我编写了一个 Spring MVC 应用程序,它显示在 XML 视图中运行的测试用例和套件的报告。我编写了很好的模型类,并且我编写了以下文件,但我猜 Handler Mapping 存在一些问题
我的 controller.java 类看起来像这样
package com.DrAssist.Fitnesse.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.DrAssist.Fitnesse.model.Suite;
@Controller
@RequestMapping("/Suite/{name}")
public class XMLController {
@RequestMapping(value="{name}", method = RequestMethod.GET, headers = "content-type=application/xml")
public @ResponseBody Suite getSuiteInXML(@PathVariable String name) {
Suite suite = new Suite("1",name,"3","Test1","4","5","7","9","550");
return suite;
}
}
我的 web.xml 文件看起来像这样
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring Web MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
dispatcher-servlet.xml 文件看起来像这样
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.DrAssist.Fitnesse.controller" />
<mvc:annotation-driven />
<!--
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean id="xmlViewer"
class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.DrAssist.Fitnesse.model</value>
</list>
</property>
</bean>
</constructor-arg>
</bean>
-->
</beans>
我收到 404 错误,控制台显示错误为
在名称为“mvc-dispatcher”的 DispatcherServlet 中找不到具有 URI [/SpringMVC/Suite/suite1] 的 HTTP 请求的映射
请咨询 似乎 /SpringMVC/Suite/suite1] 本身的 SpringMVC 部分没有通过请求。
提前致谢