0

spring mvc で安らかなサービスを作成しようとしましたが、アクセスできません。ここでたくさんの答えを読んだ後、すべてが正しいように見えます。何かが見えるかもしれません。

21.09.2013 10:50:33 org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/rest/book] in DispatcherServlet with name 'mvc-dispatcher'

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0" metadata-complete="true">

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>
                org.springframework.web.context.support.AnnotationConfigWebApplicationContext
            </param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                ru.expbrain.flib.config.RestConfig
            </param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.hmtl</welcome-file>
    </welcome-file-list>

</web-app>

RestConfig.java

package ru.expbrain.flib.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"ru.expbrain.flib.rest.controller"})
public class RestConfig  extends WebMvcConfigurerAdapter {

}

BookController.java

package ru.expbrain.flib.rest.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import ru.expbrain.flib.rest.entity.Book;

import java.util.concurrent.atomic.AtomicLong;

@Controller
public class BookController {

    private final AtomicLong counter = new AtomicLong();

    @RequestMapping(value="/book", method = RequestMethod.GET)
    public @ResponseBody Book greeting(@RequestParam(value="content", required=false, defaultValue="World") String name) {
        return new Book(counter.incrementAndGet(), name);
    }
}

パスを介してコンテンツを取得しようとします。ところで、ルート コンテキスト パスは / に移動します

http://localhost:9080/rest/book
4

1 に答える 1

0

テストしてくれた Sotirios Delimanolis に感謝します。

これはキャッシングに問題がありました...何が起こったのか説明できません。なぜなら、それはクリーニングで修復されたのではなかったからです...しかし、プロジェクトのヘルプを再作成すると、すべて問題ないようです。

于 2013-09-21T19:58:46.303 に答える