【问题标题】:Error no mapping found for HTTP request with uri in my console错误在我的控制台中找不到带有 uri 的 HTTP 请求的映射
【发布时间】:2015-02-18 17:17:03
【问题描述】:

我是 spring 新手,我正在使用 spring 制作一个小项目。我在运行项目时遇到错误。下面是我的控制器、rest-servlet-xml 和 web.xml。我找不到什么样的错误。我在我的 ECLIPSE 中使用 JBOSS6

package com.webService.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.RestController;
@RestController
@RequestMapping("/service/greeting")
public class SpringServiceController {
    @RequestMapping(value = "/{name}", method = RequestMethod.GET)
    public String getGreeting(@PathVariable String name) {
        String result="Hello "+name;        
        return result;
    }
}



<?xml version="1.0" encoding="UTF-8"?>
<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"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    <context:component-scan base-package="com.webService.controller" />
    <mvc:annotation-driven />
  </beans>

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>SpringServiceSample</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>


<servlet>
    <servlet-name>rest</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>rest</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

【问题讨论】:

  • 您能发布您的应用程序上下文吗?检查:dineshonjava.com/2014/02/…
  • 什么是我没用过的,我按照网上给出的步骤做了这个简单的项目。没有提到任何东西
  • 亲爱的 Partick,我已经检查了所有和我一样的东西,但是在我的 Eclipse 中运行时我没有发现错误,它工作正常,但是在使用 jboss6 运行时它给了我这样的错误
  • 我看到了,服务器有日志可以分享吗?您在 eclipse 中使用的是哪个服务器?

标签: spring-mvc


【解决方案1】:

您试图以这种方式访问​​其余服务:

http://localhost:8080/SpringWebService/service/greeting?name=PatrickLC

但您必须以这种方式访问​​您定义的休息服务:

http://localhost:8080/SpringWebService/service/greeting/PatrickLC

为什么? 您必须查看路径变量 (@PathVariable) 和在查询字符串中使用参数 (@RequestParam) 之间的区别。检查这个问题:

由于您正在使用 REST,我真的建议您阅读以下内容:http://www.infoq.com/minibooks/emag-rest

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    • 2012-04-16
    • 1970-01-01
    • 2017-09-17
    • 2016-06-11
    • 2017-03-02
    相关资源
    最近更新 更多