2014-12-11 2 views
1

При попытке открыть/страницу, я получаю эту ошибку:org.springframework.web.servlet.DispatcherServlet noHandlerFound, нет отображения найдено для запроса HTTP с URI

org.springframework.web.servlet.DispatcherServlet noHandlerFound

WARNING: No mapping found for HTTP request with URI [/maven-archetype-webapp/] in DispatcherServlet with name 'mvc-dispatcher'

Что случилось?

web.xml

<web-app> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>WEB-INF/app-context.xml</param-value> 
    </context-param> 
    <servlet> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value></param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
</web-app> 

WEB-INF/приложение-context.xml

<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" 
    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"> 

    <context:component-scan base-package="controller"/> 
    <context:annotation-config/> 
    <bean id="mvc-dispatcher" class="controller.Home"/> 

</beans> 

Контроллер/Home.java

package controller; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 

@Controller 
public class Home { 
    String message = "Welcome to your 1st Maven Spring project !"; 

    @RequestMapping("/") 
    public String simple1() { 
     return "simple"; 
    } 
} 
+1

Попытка добавления '' '<контекст: аннотацию-конфигурации />' ' 'в вашем app-context.xml –

+0

См. мой новый WEB-INF/app-context.xml, я добавил компонент-сканирование аннотаций-config, но проблема не решена." ПРЕДУПРЕЖДЕНИЕ: Не найдено сопоставления для HTTP-запроса с URI [/ maven-archetype-webapp /] в DispatcherServlet с именем 'mvc-dispatcher' " – Artik

+0

Решенный! :) См. Мой ответ – Artik

ответ

0

Wor KED пример:


WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>2</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

WEB-INF/диспетчеру-servlet.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:context="http://www.springframework.org/schema/context" 
    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/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd 
    "> 

    <context:component-scan base-package="controller"/> 

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/jsp/"></property> 
     <property name="suffix" value=".jsp"></property> 
    </bean> 
</beans> 

WEB-INF/JSP/simple.jsp

<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %> 

message is <b>${message}</b> 

Контроллер/Home.java

package controller; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.servlet.ModelAndView; 

@Controller 
public class Home { 
    @RequestMapping(value = "/") 
    public ModelAndView simple2() { 
     ModelAndView mav = new ModelAndView(); 
     mav.setViewName("simple"); 

     mav.addObject("message", "woohoooo1234"); 
     return mav; 
    } 
} 
Смежные вопросы