繁体   English   中英

404错误Spring MVC

[英]404 error Spring MVC

我编写了一个Spring MVC应用程序,该应用程序显示了在XML视图中运行的测试用例和套件的报告。我编写了很好的模型类,并且编写了以下文件,但是我想处理程序映射存在一些问题

我的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部分获得通过。

提前致谢

您将{name}路径变量都放在了@RequestMapping 尝试将第一个保留为@RequestMapping("Suite")

由于log语句是用DispatcherServlet编写的,并且在其中进行了很好的硬编码,因此您的代码将无法工作。 除了复制DispatcherServlet替换生成错误响应代码的代码,然后将其重定向到所需的输出之外,您几乎无能为力。

在web.xml中你声明的调度员MVC的调度员,你们给Spring配置文件名调度员servlet.xml中应该是MVC-调度-servlet.xml中。 尝试这个。

如果您已经写过

@RequestMapping(value="{name}"

比您不需要写这个,这是错误的。请更改

@RequestMapping("/Suite/{name}") 

改写

 @RequestMapping("/Suite")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM