2

この問題は解決されました。誰かが mvc-dispatcher.xml というファイルを作成しましたが、その構成が正しくありませんでした。そのファイルは、サーブレットと同じように呼び出されるため、自動的に読み込まれます。

この問題の解決に協力してくれたすべての人に感謝します。この質問は、REST インターフェースの作成方法を実際に説明しているため、ここに残しておきます。それは完全に機能します。


Spring-MVC で 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たとえば) は、どのコントローラーによっても「キャプチャ」されていないようです。私は何を間違っていますか?

他に何を試すことができるかわかりません。Java 1.7.0_15、Tomcat 7.0.34、Spring 3.1.4.RELEASE を使用しています。

私の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>

私のapplicationContext.xmlでは:

<context:component-scan base-package="com.myweb.*" />
<context:annotation-config/>
<tx:annotation-driven/>
<mvc:annotation-driven />

そして最後に、私のコントローラ クラス:

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class RestController {

    private static Logger LOG = Logger.getLogger(RestController.class);

    @RequestMapping("/asd/{test}")
    public void test(@PathVariable String test) {
        LOG.info("You sent "+test);
    }
}

メソッドの @RequestMapping を変更しようとしましたが、まだ機能しませんでした:

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

2 に答える 2

3

あなたのマッピングは間違っています。

をリクエストし/rest/asd/aaaていますが、マッピングは 用/asd/{test}です。

@RequestMapping("/asd/{test}")に変更する必要があります@RequestMapping("/rest/asd/{test}")

@RequestMapping("/rest")または、コントローラークラスに追加します

于 2013-03-01T17:09:25.777 に答える
0

@RequestMapping("/rest")url を使用してすべてのリクエストを処理するために、コントローラー クラスにも注釈を付けてみてください。

/webapp/休息/

org.springframework.web.context.ContextLoaderListenerまた、リスナーを介してコンテキストを構成する必要があります。読み込んでいないと思いますapplicationContext.xml

この部分を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>
于 2013-03-01T17:09:13.323 に答える