noHandlerFound No mapping found for HTTP request with URI [..]

16,666

Solution 1

You have @RequestMapping("method=RequestMethod.GET")

remove the quotes

@RequestMapping(method=RequestMethod.GET)

And it should work.

Solution 2

Remember things while server spring MVC project doing

  1. index.jsp(firslt starting page) should be under WebConent. not under WEB-INF not under your jsp folder(your jsp pages folder).
  2. Mapping : url pattern is like, if it is in web.xml like /
    then "/" this symbol comes at only at in controller class annotation of request mappin("/**"). no where comes. especially in request at jsp page. there is request is going to that annatation.
  3. add all jars, like ojdbc14.jar for db.
  4. autowiring is main, how bean id name in configuration file it should same as it is in your classes.
Share:
16,666
user1860447
Author by

user1860447

Updated on June 14, 2022

Comments

  • user1860447
    user1860447 almost 2 years

    I am trying out a very simple helloworld kind RestFul webservice in the Spring environment and I have been getting "org.springframework.web.servlet.DispatcherServlet noHandlerFound No mapping found for HTTP request with URI [..] in DispatcherServlet with name ..". I have tried various things but nothing is working. So far this is what I have :

    web.xml

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

    spitter-servlet.xml

    <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:mvc="http://www.springframework.org/schema/mvc"
            xmlns:context="http://www.springframework.org/schema/context"
            xsi:schemaLocation="http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            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">
    
            <mvc:annotation-driven />
    
            <context:component-scan base-package="org.resttest.bso" />
    
            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="prefix" value="/WEB-INF/views/" />
                <property name="suffix" value=".jsp" />
            </bean>
    
    </beans>
    

    And the Controller class;

    package org.resttest.bso;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.ui.ModelMap;
    
    @Controller
    @RequestMapping("/partners")
    public class PartnerController {
    
    public PartnerController(){
        System.out.println("******* From the constructor ***** " );
    }
    
    @RequestMapping("method=RequestMethod.GET")
    public String getPartner(ModelMap model){
        try{
            model.addAttribute("message", "Spring 3 MVC Hello World");
            System.out.println("******* Test message " );
        }catch(Exception ex){
            System.out.println("******* Exception thrown ... " + ex.getMessage());
        }
        return "test";
    }
    }
    

    And in WEB-INF/views/test.jsp

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
    language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <html>
    <head>
        <title>test</title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    </head>
    <body>
    <h1>Message : ${message}</h1>   
    </body>
    </html>
    

    When the server starts I also do see this : [11/28/12 9:24:02:803 EST] 00000013 DefaultAnnota I org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler Mapped URL path [/partners/method=RequestMethod.GET] onto handler 'partnerController'

    But when I try to access using url : localhost:9080/contextRoot/testWs/partners/ I get the error : [11/28/12 9:31:07:034 EST] 00000044 PageNotFound W org.springframework.web.servlet.DispatcherServlet noHandlerFound No mapping found for HTTP request with URI [/contextRoot/testWs/partners/] in DispatcherServlet with name 'spitter'

    Any help is highly appreciated. I have tried several changes based on suggestions on the forums, but nothing seems to work.

    Thanks

  • user1860447
    user1860447 over 11 years
    Wow ... That was it .... Thank you so much !!! :)
  • savv'y
    savv'y over 11 years
    You're welcome, would you mind marking this as answered.
  • user1860447
    user1860447 over 11 years
    I am really new to this. Could you please let me know how to mark this as answered ?? Thanks