I have created a spring MVC project using maven and imported it in eclipse. And mapped "/ " to controller.But whenver i run porjectit given error 404 WARNING: No mapping found for HTTP request with URI [/MyProject/] in DispatcherServlet with name 'mvc-dispatcher'
My config are : web.xml
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
HelloController.java:
@Controller
@RequestMapping("/")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Spring 3 MVC Hello World");
return "hello";
}
}
and mvc-dispatcher-servlet.xml:
<context:component-scan base-package="com.mkyong.common.controller" />
<context:annotation-config></context:annotation-config>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
Now if i change requestmapping to "/welcome" and then call url with /welcome it works. So why only for root this is not working