Mapping issues with Spring-webmvc [duplicate] - spring

This question already has answers here:
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
(13 answers)
Closed 5 years ago.
In setting up a Spring app (packaged as a WAR and hosted via Tomcat) I'm getting a 404 and the following error when I try to visit 'localhost:8080':
4479 [http-bio-8080-exec-1] WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/WEB-INF/pages/index.html] in DispatcherServlet with name 'spring'
There is most definitely a /WEB-INF/pages/index.html file.
Here's my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Additionally, here's my spring-servlet.xml file:
<?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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.company.app.controller" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value= "/WEB-INF/pages/"/>
<property name="suffix" value=".html"/>
</bean>
</beans>
And the get method from my controller:
package com.company.app.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
#Controller
public class SplashController {
#RequestMapping(value="/", method=RequestMethod.GET)
public String index() {
return "index";
}
}
So, what's wrong with my configuration?
Additionally: I'd like to include my console output from Spring's initial setup, maybe it will provide a clue or two as to what is missing:
0 [localhost-startStop-1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
92 [localhost-startStop-1] INFO org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Sun Jan 26 16:16:57 EST 2014]; root of context hierarchy
147 [localhost-startStop-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
776 [localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.company.app.controller.SplashController.index()
1547 [localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Root mapping to handler 'splashController'
1771 [localhost-startStop-1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1770 ms
Jan 26, 2014 4:16:59 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'spring'
1809 [localhost-startStop-1] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'spring': initialization started
1813 [localhost-startStop-1] INFO org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'spring-servlet': startup date [Sun Jan 26 16:16:59 EST 2014]; parent: Root WebApplicationContext
1817 [localhost-startStop-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
1947 [localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.company.app.controller.SplashController.index()
2164 [localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Root mapping to handler 'splashController'
2205 [localhost-startStop-1] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'spring': initialization completed in 396 ms

For whatever reason, changing the servlet-mapping portion of my web.xml to this solved the problem:
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

I use Spring 3.2.3 release. Try this configuration:
Correct web.xml:
<servlet-mapping>
<servlet-name>Spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
Correct Spring-servlet.xml:
<context:component-scan base-package="your.package.controller"/>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean id="internalViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp"/>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
Correct mapping annotacion:
#RequestMapping(value="/index", method=RequestMethod.GET)
And create index.jsp file.

I also faced the same problem when a friend of mine suggest me to check for the package declaration.
After I knew for which package the definition of the controller request mapping and context:component-scan base-package to check for I saw it was not the same and after giving it the proper package name it started to work.
Check for the following snippet in your Spring config file
<context:component-scan base-package="your package name" >

Related

I wrote a simple spring MVC program using maven which is throwing 404 error when i click the login button to redirect

Jul 18, 2017 8:45:43 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/hello-servlet.xml] Jul 18, 2017 8:45:44 PM org.springframework.web.servlet.DispatcherServlet initServletBean INFO: FrameworkServlet 'hello': initialization completed in 580 ms Jul 18, 2017 8:45:44 PM org.springframework.web.servlet.PageNotFound noHandlerFound WARNING: No mapping found for HTTP request with URI [/HelloWorld/faisal] in DispatcherServlet with name 'hello'
hello-servlet.xml
you need to load ApplicationContext.xml in web.xml file, you can use sample bellow code for adding ApplicationContext.xml in web.xml
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:ApplicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
First if you want to get any response from your controller with your method declared as VOID you don't go to get any response, your method is printing in console the string faisl. Then if you want to get the index page that prints "faisal" you need to declare the controller like this:
#Controller
public class MainClass {
#RequestMapping(value="/faisal", method=RequestMethod.GET)
public ModelAndView getIndex(){
return new ModelAndView("index", "msg", "Hello Faisal");
}
}
in your hello-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:ctx = "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-2.5.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-2.5.xsd">
<ctx:component-scan base-package="com.faisal"></ctx:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
now the InternalViewResolver is looking for your index.jsp view that you have declared under /WEB-INF/
In your index.jsp you can do the next to print the message that you has mapped to your view:
<body>
<h1>${msg}</h1>
</body>
${msg} is the key that you are passing in the controller the value is Hello faisal then if you open the url
/HelloWorld/faisal
in your view you should be able to see Hello Faisal
Regards,

HTTP Status 404 - No handler mapping found

Having some issues while running the below code:
Web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>To do List</display-name>
<welcome-file-list>
<welcome-file>login.do</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/todo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
-------------- todoservlet.xml -------------
<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-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.in28minutes" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:resources mapping="/webjars/**" location="/webjars/"/>
</beans>
-------------- login.jsp -------------
<html>
<head>
<title>Login Page</title>
</head>
<body>
<p><font color="red">${errorMessage}</font></p>
<form action="login.do" method="POST">
Name : <input name="name" type="text" />
Password : <input name="password" type="password" />
<input type="submit" />
</form>
</body>
</html>
-------------- Controller -------------
package com.in28minutes.login;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
#Controller
#SessionAttributes("name")
public class LoginController {
#Autowired
private LoginService loginService;
#RequestMapping(value = "/login", method = RequestMethod.GET)
public String showLoginPage() {
return "login";
}
#RequestMapping(value = "/login", method = RequestMethod.POST)
public String handleUserLogin(ModelMap model, #RequestParam String name,
#RequestParam String password) {
if (!loginService.validateUser(name, password)) {
model.put("errorMessage", "Invalid Credentials");
return "login";
}
model.put("name", name);
return "welcome";
}
}
-------------- getting error message -------------
URL: http://localhost:8080/in28Minutes27-springmvc/
------------browser error --------------
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
Apache Tomcat/8.0.39
----------------- log on console ---------------------
TRACE 2016-12-20 12:14:32,152 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Bound request context to thread: org.apache.catalina.connector.RequestFacade#df024db
DEBUG 2016-12-20 12:14:32,153 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/in28Minutes27-springmvc/]
TRACE 2016-12-20 12:14:32,155 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#1a6fbdb3] in DispatcherServlet with name 'dispatcher'
DEBUG 2016-12-20 12:14:32,156 [http-nio-8080-exec-2] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /login.do
DEBUG 2016-12-20 12:14:32,156 [http-nio-8080-exec-2] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/login.do]
TRACE 2016-12-20 12:14:32,157 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping#24b1f9e9] in DispatcherServlet with name 'dispatcher'
TRACE 2016-12-20 12:14:32,158 [http-nio-8080-exec-2] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping - No handler mapping found for [/login.do]
TRACE 2016-12-20 12:14:32,158 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#1f358bf7] in DispatcherServlet with name 'dispatcher'
TRACE 2016-12-20 12:14:32,159 [http-nio-8080-exec-2] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - No handler mapping found for [/login.do]
WARN 2016-12-20 12:14:32,159 [http-nio-8080-exec-2] org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/in28Minutes27-springmvc/] in DispatcherServlet with name 'dispatcher'
TRACE 2016-12-20 12:14:32,159 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade#df024db
DEBUG 2016-12-20 12:14:32,159 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Successfully completed request
TRACE 2016-12-20 12:14:32,159 [http-nio-8080-exec-2] org.springframework.web.context.support.XmlWebApplicationContext - Publishing event in WebApplicationContext for namespace 'dispatcher-servlet': ServletRequestHandledEvent: url=[/in28Minutes27-springmvc/]; client=[0:0:0:0:0:0:0:1]; method=[GET]; servlet=[dispatcher]; session=[null]; user=[null]; time=[23ms]; status=[OK]
I am not able to resolve this issues; any help is appreciated.
The problem in your web.xml file. You cannot use .do extension as a welcome file, It should be valid presentation file with extension i.e .html, .jsp etc
Replace below block of code in your web.xml file
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
Hope it will work for you.
More Details:
when you don't have any handler methods to handle that path. Add one. Or add a <welcome-file> to your deployment descriptor, ie. the web.xml.
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
assuming the index.jsp is at the root of the WAR, ie. outside WEB-INF.

404 error while running Spring MVC webapp

While I am running the spring mvc dynamic web-app.It does not give any exception
in console but 404 error in browser and in console these I got.
INFO: Loading XML bean definitions from ServletContext resource [/WEB-
INF/troubleshootApplicationContext.xml]
11-Apr-2016 08:47:59 org.springframework.web.context.ContextLoader
initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 360 ms
11-Apr-2016 08:47:59 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'HelloWeb'
11-Apr-2016 08:47:59 org.springframework.web.servlet.FrameworkServlet
initServletBean
INFO: FrameworkServlet 'HelloWeb': initialization started
11-Apr-2016 08:47:59
org.springframework.context.support.AbstractApplicationContext
prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'HelloWeb-servlet':
startup
date [Mon Apr 11 08:47:59 BST 2016]; parent: Root WebApplicationContext
11-Apr-2016 08:47:59
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-
INF/dispatcher-servlet.xml]
11-Apr-2016 08:47:59
org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
registerHandler
INFO: Mapped URL path [/hello] onto handler 'troubleController'
11-Apr-2016 08:47:59
org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
registerHandler
INFO: Mapped URL path [/hello.*] onto handler 'troubleController'
11-Apr-2016 08:47:59
org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
registerHandler
INFO: Mapped URL path [/hello/] onto handler 'troubleController'
11-Apr-2016 08:47:59 org.springframework.web.servlet.FrameworkServlet
initServletBean
INFO: FrameworkServlet 'HelloWeb': initialization completed in 495 ms
11-Apr-2016 08:47:59 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
11-Apr-2016 08:47:59 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
11-Apr-2016 08:47:59 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/21 config=null
11-Apr-2016 08:47:59 org.apache.catalina.startup.Catalina start
INFO: Server startup in 1490 ms
11-Apr-2016 08:48:00 org.springframework.web.servlet.DispatcherServlet
noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TS_WEB_APP/] in
DispatcherServlet with name 'HelloWeb'
Web.xml
====
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-
class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
dispatcher-servlet.xml
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
Here is the controller that i used
#Controller
//#RequestMapping("/hello")
public class TroubleController {
#RequestMapping(value = "/hello")
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello11";
}
}
you have mapped all the URL's containing /hello to the troubleController , so in order to check that response , you could try and hit localhost:8080/YourWebAppName/hello , and replace the YourWebAppName with your web application project name.
The error that you get , indicates that for the URL /TS_WEB_APP/ there has not been set up any #RequestMapping to any controller
dispatcher servlet
==========
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.myriad.ihc.controller" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
Web.xml
==========
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
Spring MVC Application
index.jsp
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/*</url-pattern>
This is my controller class and also i changed my my jsp page location to /WEB-INF/
#Controller
public class TroubleController {
#RequestMapping(value = "/hello")
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello11";
}
}

Spring No mapping found for HTTP request with URI

I looked at everypost related with this problem and tried nearly all of them. I'm getting this error. I also have created an empty Spring Maven MVC project and duplicated view and controller and named them as example.jsp and ExampleController.java etc. Shortly, I can not get any respond from Tomcat. I do not know it has anything to do with it but I' also getting and error at the beginning of Console log.
Thanks in advance...
Console log beginning warning (I do not know it has an affect on this problem):
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpitterSpring' did not find a matching property.
Here is my actual part of error:
Tem 11, 2014 4:55:32 PM org.springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler
INFO: Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
Tem 11, 2014 4:55:32 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'appServlet': initialization completed in 885 ms
Tem 11, 2014 4:55:32 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Tem 11, 2014 4:55:32 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Tem 11, 2014 4:55:32 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9260 ms
Tem 11, 2014 4:55:34 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/spitter/] in DispatcherServlet with name 'appServlet'
Tem 11, 2014 4:55:39 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/spitter/spitter/deneme] in DispatcherServlet with name 'appServlet'
Tem 11, 2014 4:55:45 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/spitter/deneme] in DispatcherServlet with name 'appServlet'
Tem 11, 2014 4:55:52 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/spitter/deneme] in DispatcherServlet with name 'appServlet'
Here is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/application-config.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Here is my servlet-context.xml file
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<context:component-scan base-package="com.ex.spitter.mvc" />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
</beans:beans>
Here is my com.ex.spitter.mvc -> HomeController:
package com.ex.spitter.mvc;
import java.util.Map;
import javax.inject.Inject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.ex.spitter.service.SpitterService;
#Controller
public class HomeController {
private SpitterService spitterService;
#Inject
public HomeController(SpitterService spitterService) {
this.spitterService = spitterService;
}
#RequestMapping(value = { "/", "/home" }, method = RequestMethod.GET)
public String showHomePage(Map<String, Object> model) {
model.put("spittles", spitterService.getRecentSpittles(spittlesPerPage));
return "home";
}
// <start id="spittlesPerPage"/>
public static final int DEFAULT_SPITTLES_PER_PAGE = 25;
private int spittlesPerPage = DEFAULT_SPITTLES_PER_PAGE;
public void setSpittlesPerPage(int spittlesPerPage) {
this.spittlesPerPage = spittlesPerPage;
}
public int getSpittlesPerPage() {
return spittlesPerPage;
}
// <end id="spittlesPerPage"/>
}
The problem was not solved but I changed my workspace and try to do it copy the codes. Besides, I will try to use a different version of Tomcat or install a Jboss

Request not addressed by spring controller

I have configured in following way that spring MVC app using Spring 3.1.1.RELEASE
web.xml
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/context/*-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/cgi/*</url-pattern>
</servlet-mapping>
springmvc-servlet.xml
<context:component-scan base-package="com.pokuri.mvc.controllers"/>
UserController.java
package com.pokuri.mvc.controllers;
#Controller
#RequestMapping("/user")
public class UserController {
#RequestMapping(method=RequestMethod.GET)
#ResponseBody
public String defaultRequest(){
return "It's a default handler method";
}
}
index.jsp
<a class="action" href="cgi/user">Default Action</a>
Sever log on initializing springmvc app:
23:53:04,406 INFO [DispatcherServlet] FrameworkServlet 'springmvc': initialization started
23:53:04,468 INFO [XmlWebApplicationContext] Refreshing WebApplicationContext for namespace 'springmvc-servlet': startup date [Thu Jun 28 23:53:04 IST 2012]; root of context hierarchy
23:53:04,609 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/context/services-context.xml]
23:53:04,890 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#6c4fe: defining beans [dummyService]; root of factory hierarchy
23:53:05,156 INFO [DispatcherServlet] FrameworkServlet 'springmvc': initialization completed in 750 ms
.....
.....
23:56:17,875 WARN [PageNotFound] No mapping found for HTTP request with URI [/springmvc/cgi/user] in DispatcherServlet with name 'springmvc'
When I click on that link in index.jsp, I am getting 404 error. I thing I might have done a silly mistake. But, not able to track it. Can someone help me in this?
It looks like your DispatcherServlet is looking for config files ending in -context.xml. But your Spring config file is called springmvc-servlet.xml.

Resources