Сопоставление запроса Spring MVC не найдено Страница 404 не найдена

Я разрабатываю пример приложения Spring MVC. Я хочу вернуть строку JSON, запросив контроллер Spring MVC, но когда я делаю запрос через URL-адрес, он показывает мне ошибку 404. Я следую учебнику с очень известного веб-сайта. Мой URL-адрес, на который я делаю запрос, IS localhost:8080/SpringAngularProject/rest/kfc/brands/kfc1 вот мой код ниже:

0-- Console Picture : 
Aug 12, 2014 7:31:19 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringAngularProject/rest/kfc/brands/sdsd] in DispatcherServlet with name 'mvc-dispatcher'

1- Это мой класс контроллера

package com.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;

@Controller
@RequestMapping("/kfc/brands")
public class HelloWorldController {

    @RequestMapping(value = "{name}", method = RequestMethod.GET)
    public @ResponseBody Shop getShopInJSON(@PathVariable String name) {

        Shop shop = new Shop();
        shop.setName(name);
        shop.setStaffName(new String[] { "staff1", "staff2" });
        return shop;

    }
}

2-- Мой файл 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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>AngularSpring</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
  <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>
  <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>

3 -- Мой файл конфигурации Spring:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    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.controller.HelloWorldController" />
        <mvc:annotation-driven /> 

</beans>

4-- Мой файл pom.xml для maven

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>SpringAngularProject</groupId>
    <artifactId>SpringAngularProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <spring.version>3.2.2.RELEASE</spring.version>
        <jackson.version>1.9.10</jackson.version>
        <jdk.version>1.7</jdk.version>
    </properties>

    <dependencies>

        <!-- Spring 3 dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.12</version>
        </dependency>




    </dependencies>
</project>

person Junaid Akhtar    schedule 12.08.2014    source источник
comment
@RequestMapping(value = "/kfc/brands/{name}" при проверке вашего метода   -  person AlexGreg    schedule 12.08.2014
comment
@AlexGreg тоже не работает   -  person Junaid Akhtar    schedule 12.08.2014
comment
Попробуйте изменить <url-pattern>/rest</url-pattern> на <url-pattern>/rest/*</url-pattern> и дайте мне знать   -  person geoand    schedule 12.08.2014
comment
Нет, та же проблема :( @geoand   -  person Junaid Akhtar    schedule 12.08.2014
comment
Вы развернули свое приложение в контексте SpringAngularProject?   -  person geoand    schedule 12.08.2014
comment
да, мой проект называется SpringAngularProject @geoand   -  person Junaid Akhtar    schedule 12.08.2014
comment
@geoand после перехода на консоль rest/* выдает мне эту ошибку: ПРЕДУПРЕЖДЕНИЕ: не найдено сопоставление для HTTP-запроса с URI [/SpringAngularProject/rest/kfc/brands/sdsd] в DispatcherServlet с именем «mvc-dispatcher»   -  person Junaid Akhtar    schedule 12.08.2014
comment
Можете ли вы обновить свой вопрос с выводом журналов в режиме debug при выполнении запроса?   -  person geoand    schedule 12.08.2014
comment
Не могли бы вы попробовать localhost:8080/rest/kfc/brands/sdsd? Спасибо   -  person geoand    schedule 12.08.2014
comment
Все еще не работает @geoand   -  person Junaid Akhtar    schedule 12.08.2014
comment
Вы пробовали URL, который я предложил вместе с отображением /rest/*?   -  person geoand    schedule 12.08.2014
comment
@geoand да, я устал от этого, выдайте мне эту ошибку /sdsd] в DispatcherServlet с именем «mvc-dispatcher»   -  person Junaid Akhtar    schedule 12.08.2014
comment
Сообщение предполагает, что вы добавили SpringAngularProject к URL-адресу. Вы уверены, что тестировали без него?   -  person geoand    schedule 12.08.2014
comment
да я устал это много раз все еще не работает :( @geoand   -  person Junaid Akhtar    schedule 12.08.2014
comment
Если вы посмотрите журналы, Spring сообщит вам, какие URL-адреса сопоставлены. Пожалуйста, сначала посмотрите туда. Если он не зарегистрирован, ваш контроллер не будет обнаружен при сканировании компонентов.   -  person Bart    schedule 12.08.2014
comment
В логе нет ссылок что делать   -  person Junaid Akhtar    schedule 12.08.2014


Ответы (1)


Наконец, я сам получил свой ответ, просто вместо <context:component-scan base-package="com.controller.HelloWorldController" /> я изменил на <context:component-scan base-package="com.controller" />, нам просто нужно указать путь до базового пакета, как следует из названия.

person Junaid Akhtar    schedule 12.08.2014