Java 固定:“;未找到映射";尝试使用SpringMVC设置RESTfull接口

Java 固定:“;未找到映射";尝试使用SpringMVC设置RESTfull接口,java,rest,spring-mvc,Java,Rest,Spring Mvc,这个问题解决了。有人创建了一个名为mvc-dispatcher.xml的文件,该文件的配置不正确。该文件是自动加载的,因为它的调用与servlet相同 我要感谢所有试图帮助我解决这个问题的人。我将这个问题保留在这里,因为它实际上解释了如何创建REST接口。它工作得很好 我正试图用SpringMVC建立一个RESTful接口。服务器启动时不会出现问题,但每当我尝试调用REST接口时,都会收到以下消息: 41 WARN [springframework.web.servlet.PageNotFou

这个问题解决了。有人创建了一个名为mvc-dispatcher.xml的文件,该文件的配置不正确。该文件是自动加载的,因为它的调用与servlet相同

我要感谢所有试图帮助我解决这个问题的人。我将这个问题保留在这里,因为它实际上解释了如何创建REST接口。它工作得很好


我正试图用SpringMVC建立一个RESTful接口。服务器启动时不会出现问题,但每当我尝试调用REST接口时,都会收到以下消息:

41 WARN [springframework.web.servlet.PageNotFound] No mapping found for HTTP request with URI [/myweb/rest/asd/aaa] in DispatcherServlet with name 'mvc-dispatcher'
似乎我正在发送的URL(
http://localhost:8080/myweb/rest/asd/qwe
例如)未被任何控制器“捕获”。我做错了什么

我不知道我还能尝试什么。我正在使用Java1.7.0_15、Tomcat7.0.34和Spring3.1.4.RELEASE

在my web.xml中:

<?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_3_0.xsd" id="WebApp_ID" version="3.0">

<display-name>MyWeb</display-name>
<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>

<!-- Listener for MVC spring -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<!-- Servlet for MVC spring --> 
<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>/rest/*</url-pattern>
</servlet-mapping>

<!-- Loading web properties -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
尝试更改方法的@RequestMapping,但仍然无效:

@RequestMapping(method=RequestMethod.GET)
public void test() {
    LOG.info("You sent something");
}

尝试使用
@RequestMapping(“/rest”)
注释控制器类,以处理带有url的所有请求

/webapp/rest/

您还应该通过
org.springframework.web.context.ContextLoaderListener
listener配置您的上下文。我认为您没有加载
applicationContext.xml

<!--spring bootstrap listener  -->
<context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>/WEB-INF/config/applicationContext.xml</param-value>  
</context-param>


<listener>  
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
</listener>
将此部分添加到您的
web.xml

<!--spring bootstrap listener  -->
<context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>/WEB-INF/config/applicationContext.xml</param-value>  
</context-param>


<listener>  
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
</listener>

上下文配置位置
/WEB-INF/config/applicationContext.xml
org.springframework.web.context.ContextLoaderListener
您的映射错误

您正在请求
/rest/asd/aaa
,但您的映射用于
/asd/{test}

您需要将
@RequestMapping(“/asd/{test}”)
更改为
@RequestMapping(“/rest/asd/{test}”)


或者将
@RequestMapping(“/rest”)
添加到控制器类中

请求的URL是什么?请阅读帖子URL请求是
http://localhost:8080/myweb/rest/asd/qwe
非常感谢您的回复!试图将
@RequestMapping(“/rest”)
添加到类中,但得到了相同的结果。另外,将方法的RequestMapping更改为
@RequestMapping(“/rest/asd/{test}”)
(删除类的RequestMapping)也不起作用。是否确实加载了控制器?我的applicationContext.xml中有一行:
。controller类位于com.myweb.media.controller中,非常感谢您的回复。尝试了这个方法,还尝试将方法的请求改为
@RequestMapping(“/rest/asd/{test}”)
,但这两种方法都不起作用。嗯,您正在扫描要加载的控制器吗?我的applicationContext.xml中有一行:
。控制器类位于com.myweb.media中。controller@Calabacin你在我发布的web.xml中添加了新的部分了吗?很抱歉,我的web.xml中没有包含这一部分,我试图通过不包含JSF部分来保持简单,结果我删除了超出预期的部分。我在原来的帖子中更新了web.xml
<!--spring bootstrap listener  -->
<context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>/WEB-INF/config/applicationContext.xml</param-value>  
</context-param>


<listener>  
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
</listener>