RequestMappingHandlerMapping.getHandlerInternal:230 - Did not find handler method for
Asked Answered
V

4

6

trying to make some spring example program - constantly getting the error - it happens that my controller cannot handle /hello request. Here is debug info from log4j.

    13:50:58,502 {TRACE} DispatcherServlet.initContextHolders:1018 - Bound request context to thread: org.apache.catalina.connector.RequestFacade@636f2067
    13:50:58,503 {DEBUG} DispatcherServlet.doService:823 - DispatcherServlet with name 'springtest' processing GET request for [/springtest_2/hello]
    13:50:58,504 {TRACE} DispatcherServlet.getHandler:1088 - Testing handler map         
[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@7bab2c3] in DispatcherServlet with name 'springtest'
    13:50:58,504 {DEBUG} RequestMappingHandlerMapping.getHandlerInternal:220 - Looking          
    up handler method for path /hello
    13:50:58,504 {DEBUG} RequestMappingHandlerMapping.getHandlerInternal:230 - Did not find handler method for [/hello]
    13:50:58,504 {TRACE} DispatcherServlet.getHandler:1088 - Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@722e242b] in         DispatcherServlet with name 'springtest'
    13:50:58,505 {TRACE} BeanNameUrlHandlerMapping.getHandlerInternal:127 - No handler mapping found for [/hello]
    13:50:58,505 {WARN} PageNotFound.noHandlerFound:1108 - No mapping found for HTTP request with URI [/springtest_2/hello] in DispatcherServlet with name 'springtest'  
    13:50:58,505 {TRACE} DispatcherServlet.resetContextHolders:1028 - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@636f2067
    13:50:58,505 {DEBUG} DispatcherServlet.processRequest:966 - Successfully completed request
    13:50:58,506 {TRACE} XmlWebApplicationContext.publishEvent:332 - Publishing event in WebApplicationContext for namespace 'springtest-servlet': ServletRequestHandledEvent: url=[/springtest_2/hello]; client=[0:0:0:0:0:0:0:1]; method=[GET]; servlet=[springtest]; session=[null]; user=[null]; time=[9ms]; status=[OK]

web.xml from my project.

    <?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>Spring3-Hibernate DEMO</display-name>

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
</context-param>

<!-- The front controller of this Spring Web application, responsible for handling all  application requests -->
<servlet>
    <servlet-name>springtest</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/springtest-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
    <servlet-name>springtest</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

</web-app>

spring-test-servlet.xml - dispatcher file from my project

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

<mvc:annotation-driven />

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

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

ControllerMain.java - from my project

package com.denmroot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class ControllerMain {

@RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String helloworld (ModelMap model) {
    model.addAttribute("message", "Hello World !!! Spring Output");
    return "hello";     
}

}
Vivienne answered 27/7, 2014 at 11:15 Comment(5)
possible duplicate of Spring invokes wrong controller mappingAilin
Changing Url-pattern to \ dont resolve problem. <!-- Map all requests to the DispatcherServlet for handling --> <servlet-mapping> <servlet-name>springtest</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>Vivienne
Don't understand what you mean duplicate of Spring - read the link, see nothing related to my question.Vivienne
It is showing wrong file name <param-value>/WEB-INF/springtest-servlet.xml</param-value> It should be spring-test-servlet.xmlLakeishalakeland
Wrong file name in question, It should be springtest-servlet.xml off course.Vivienne
H
1

For me, I had a typo in the Spring config file which points to the package:

Was:

<context:component-scan base-package="com.something.web.controlers" />

Fixed with correct spelling:

<context:component-scan base-package="com.something.web.controllers" />
Hyperthermia answered 24/11, 2016 at 9:49 Comment(1)
Arrrr - that was it for me. >>> Case matters.Madera
C
1

ControllerMain.java requires a @RequestMapping("/") statement after the @Controller.

Change:

@Controller
public class ControllerMain {

@RequestMapping(value = "/hello", method = RequestMethod.GET)
....
....

To:

@Controller
@RequestMapping("/")
public class ControllerMain {

@RequestMapping(value = "/hello", method = RequestMethod.GET)
....
....
....
Carmelcarmela answered 9/5, 2017 at 0:1 Comment(0)
P
0

Actually the log says everything:

  • Or change your url from client to just /hello path

  • Or map your @Controller with:

    @Controller
    @RequestMapping("/springtest_2")
    public class ControllerMain {
    
Pity answered 27/7, 2014 at 12:10 Comment(13)
Thanks for your answer but mapping controller with ("/springtest_2") didn't help still get the same error.Vivienne
Does your context really configure mapping for your annotated class? Is your ControllerMain within web-app classloader?Pity
You mean <context:component-scan base-package="com.denmroot.controller"/> - Yes Controller is within com.denmroot.controller container.Vivienne
github.com/DENMROOT/spring_mvc_test - feel free to inspect my project on github.Vivienne
Right. I see. But is it really as a bean in the application context? Seems for me you can see in logs some mapping info on application startup.Pity
url-pattern should be <url-pattern>/*</url-pattern>. It's from your GH projectPity
RequestMappingHandlerMapping.getHandlerInternal:220 - Looking up handler method for path / RequestMappingHandlerMapping.getHandlerInternal:230 - Did not find handler method for [/] [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@7bab2c3] in DispatcherServlet with name 'springtest' 15:52:58,120 {TRACE} BeanNameUrlHandlerMapping.getHandlerInternal:127 - No handler mapping found for [/] 15:52:58,120 {WARN} PageNotFound.noHandlerFound:1108 - No mapping found for HTTP request with URI [/springtest_2/] in DispatcherServlet with name 'springtest'Vivienne
When I try /* for url-pattern - get same errors but with [/] instead of [/hello]Vivienne
I dont have builded WAR file, just testing app in eclipse Tomcat server. Or i don't understand what you need :)Vivienne
:) not to day. sorry: weekend. Seems for me you talk russian: Безымянный.jpg :)Pity
Викенд сидя за экраном монитора :) жаль, очень надо разобраться с проблемой.Vivienne
Ага, поймал! Просто надо сейчас уходитьPity
:) skype: denmroot - будет время и желание, буду очень благодарен помощи.Vivienne
P
0

@Controller

annotation is missing for your controller class.

Penitentiary answered 19/5, 2015 at 3:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.