Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.springframework.web.servlet.PageNotFound noHandlerFound; WARNING: No mapping found for HTTP request with URI in DispatcherServlet

I went through many forums and blogs to get the answer but couldn't get any useful tip or advice. So please if anybody can help in below issue it would be a great help.

I am getting the below Warning and error when tried to connect to http://localhost:8080/SpringApp/hello :

INFO: Server startup in 6935 ms
Jul 19, 2014 11:15:42 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringApp/] in DispatcherServlet with name 'HelloWeb'
Jul 19, 2014 11:16:29 AM com.example.java.HelloController printHelloWorld
INFO: HelloController : printHelloWorld : ENTER
Jul 19, 2014 11:16:29 AM com.example.java.HelloController printHelloWorld
INFO: HelloController : printHelloWorld : EXIT
Jul 19, 2014 11:16:29 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringApp/WEB-INF/jsp/hello.jsp] in DispatcherServlet with name 'HelloWeb'

because of this I am getting HTTP Status 404 error in Tomcat.

The whole data is provided below:

The web.xml file is :

<display-name>Spring MVC Application</display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<servlet>
    <servlet-name>HelloWeb</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/HelloWeb-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>HelloWeb</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

The HelloWeb-Servlet.xml file is :

<?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:mvc="http://www.springframework.org/schema/mvc" 
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd 
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.example.java"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>
<context:annotation-config/>
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>
</beans>

The HelloController.java file is :

package com.example.java;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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
@RequestMapping("/hello")
public class HelloController {

    protected final Log logger = LogFactory.getLog(getClass());

    @RequestMapping(method=RequestMethod.GET)
    public String printHelloWorld(ModelMap model){
        logger.info("HelloController : printHelloWorld : ENTER");
        model.addAttribute("message", "Hello Sumit");
        logger.info("HelloController : printHelloWorld : EXIT");
        return "hello";
    }
}
like image 445
Sumit Surana Avatar asked Jul 19 '14 06:07

Sumit Surana


1 Answers

Firstly, the file name should be HelloWeb-servlet.xml (servlet 's' lowercase). If still you have some problem try adding

<mvc:default-servlet-handler/>

in HelloWeb-servlet.xml

like image 81
Nickhil Avatar answered Sep 28 '22 22:09

Nickhil