Reputation: 3
Please have a look at the first line and last line logged in my console. first line declares that /SpringMVC/welcome is mapped on to helloController but the last line in the log shows otherwise!
Background: I have taken the source straight from MyKong and tried to run. I haven't changed any configurations, except for changing @RequestMapping("/welcome") to @RequestMapping("/SpringMVC/welcome"). Full source available here
INFO: Mapped URL path [/SpringMVC/welcome] onto handler 'helloController'
Jul 2, 2014 8:17:54 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/SpringMVC/welcome.*] onto handler 'helloController'
Jul 2, 2014 8:17:54 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/SpringMVC/welcome/] onto handler 'helloController'
Jul 2, 2014 8:17:54 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'mvc-dispatcher': initialization completed in 231 ms
Jul 2, 2014 8:17:54 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 2, 2014 8:17:54 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 2, 2014 8:17:54 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2249 ms
Jul 2, 2014 8:17:55 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVC/] in DispatcherServlet with name 'mvc-dispatcher'
Jul 2, 2014 8:18:03 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVC/welcome] in DispatcherServlet with name 'mvc-dispatcher'
Controller Code:
package com.mkyong.common.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
@RequestMapping("/SpringMVC/welcome")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Spring 3 MVC Hello World");
return "hello";
}
}
Upvotes: 0
Views: 347
Reputation: 279880
Yeah. Your controller method is mapped to
/SpringMVC/welcome
relative to your context path.
That is, if your context path is
/SpringMVC
, then the request needs to be sent to
/SpringMVC/SpringMVC/welcome
Upvotes: 1