This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes RequestMappingHandlerMapping - Did not find handler method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "RequestMappingHandlerMapping - Did not find handler method" Watch "RequestMappingHandlerMapping - Did not find handler method" New topic
Author

RequestMappingHandlerMapping - Did not find handler method

Andrea Nobili
Greenhorn

Joined: Nov 08, 2012
Posts: 21
I have develop this example basing uppon the Spring MVC Showcase example.

The result I want to achieve is as follows: a web application that manage 2 kinds of HTTP Request:

FIRST HTTP Request type:: HTTP request towards resources having a structure [/b]/folder[/b]

SECOND HTTP Request type: HTTP request towards resources having a structure [/b]/file.html[/b]

The showcase example manage by default the first type of HTTP Request, so I have add an other DispatcherServlet in my web.xml configuration file to manage the HTTP Request towards *.html pattern but I am finding some problem to handle the second type of request

So this is my web.xml code:



As you can see in this web.xml fine I have defined 2 DispatcherServlet: the first one that manage the first type of HTTP Request and the second one that manage the second type.

Ok, the DispatcherServlet that manage the HTTP Request towards resources having form: file.html have servlet-name=appServlet2 and it is configured by the servlet2-context.xml configuration file.

This is the code of servlet2-context.xml:



this is a "copy" of the servlet-context.xml file that configure the original DispatcherServlet of the example, the only difference, made by me, is that I import a different file: controller2.xml

This file simply specify the package in wich are actived the component scan managed by this servlet:


So, for this servlet is actived the component scan that search annotation in the following package: org.springframework.samples.mvc2.simple

Ok...In this package I have created the following controller class:



As you can see the sayHello method is annoted by @RequestMapping("/hello") annotation and, in theory, have to manage HTTP Request towards /hello.html file !!!

But don't work well !!!

Adding in my home.jsp view I add these links:


When I click on these links I have the following error message:

HTTP Status 404
....
- description The requested resource is not available.


And this is my stacktrace:



So it is clear that Spring have loaded the appServlet2 DispatcherServlet (the DispatcherServlet that is configured to manage HTTP Request toward filename.html resources) but don't find a mapping for the hello.html resources...

If I change the @RequestMapping("/hello") annotation in @RequestMapping("/hello.html") for my method (inside my HelloController class) the example run well !!!
Using the "/hello.html" pattern inside the @RequestMapping annotation, Spring find the mapping with my sayHello() method and all run well !!!

Infact this is the relative stack trace (the HTTP reuqest is is properly managed by appServlet2 DispatcherServlet and the sayHello() method is called)



I think that this behavior is very very strange because the appServlet2 is configured to handle automatically HTTP request toward resources shaped as: "filename.html" because I have mapped this kind of resources in my web.xml file by the tag:



But if I don't specify that the .html in the @RequestMapping annotation don't work...

The strange thing is that I have created an other simplify Spring project (outside the Spring MVC Showcase Project) and in this one I have not this mapping problem...

Why? Someone can help me to understand this thing? I am going crazy

Thank you very much for your attenction
Andrea


Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

whenever a request is made for "*.html" it invokes the servlet with url-pattern "/", which is your dispatcherservlet1, in this xml you don't have request mapping so this exception is thrown..

Already, when you map "/" (All) requests to spring dispatcher servlet, what's the need creating a new dispatcher servlet for *.html?


Regards, Prasad
SCJP 5 (93%)
Andrea Nobili
Greenhorn

Joined: Nov 08, 2012
Posts: 21
Prasad Krishnegowda wrote:whenever a request is made for "*.html" it invokes the servlet with url-pattern "/", which is your dispatcherservlet1, in this xml you don't have request mapping so this exception is thrown..

Already, when you map "/" (All) requests to spring dispatcher servlet, what's the need creating a new dispatcher servlet for *.html?


mmm...maybe I have not totaly understand what you want explain me...

what do you mean when you say me that: "in this xml you don't have request mapping so this exception is thrown? Which file you mean?

If you speak about web.xml I think that in this file I have specify the mapping for "*.html" HTTP Request that that must be managed by my SECOND DispatcherServlet named appServlet2, infact in my web.xml file I have declared these 2 tags:

The first one to create a new instance for DispatcherServlet named appServlet2


The second one to map towards this DispatcherServlet all the HTTP Request having pattern "*.html"



You also say me that: whenever a request is made for "*.html" it invokes the servlet with url-pattern "/" (that is the first one named appServlet) but this is not true !!!

When an HTTP request is made for "*.html" it is not invoked the first DispatcherServlet but seems that is invoked the second one (appServlet2) that is configured to handle exactly "*.html" HTTP Request, infact if I click on my link: "Get HELLO.html" in my stack trace I have:



In the first line you can see that the request direct to: "/spring-mvc-showcase/hello.html" is managed by my second DispatcherServlet named "appServlet2" that is configured to handle "*.html" http request....and even more...if I delete the previus 2 tags (to create the instance and the mapping for appServlet2 DispatcherServlet), if click on this links the application can not manage "*.html" request and goes into error...

So, seems that use the right DispatcherServlet for request having form "*.html" but the strange thing is that in this example to work well I have to use @RequestMapping("/hello.html") to annotate my method, and so run well and the method is mapped for my hello.html http request.



If I use this form it is all ok...but I think that it is very strange and have to work using @RequestMapping("/hello")

why?

I am doing this "experiment" to understand well the mapping logic of Spring MVC framework...it is just an experiment to learn how Spring MVC work...

Thank you very much
Andrea





 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: RequestMappingHandlerMapping - Did not find handler method
 
Similar Threads
javax.servlet.ServletException: No adapter for handler
STS springMVC project how to run on tomcat application
Some beginner question about annotation configuration in Spring 3.1
javax.servlet.ServletException: Could not resolve view with name home-- apache Velocity, spring
REST web service return both XML or JSON