I am following this Spring Docs and configured web.xml and applicatioinContext.xml to use feature Single root context in Spring Web MVC i.e. there is no Servlet WebApplicationContext; all request will be served by Root WebApplicatioinContext.
But problem is HTTP requests are not being delegated to controllers of root WebApplicationContext.
web.xml:
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/root-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
root-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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">
<bean id="PostController" class="org.my.controllers.PostController">
</bean>
</beans>
Controller:
@Controller
public class PostController {
@RequestMapping(value= "/controller", method = RequestMethod.GET)
@ResponseBody
public String foo() {
return "Response!";
}
}
So When I hit URL http://localhost:8080/PracticeJavaWeb/controller in browser it is showing 404
Server log saying:
WARNING: No mapping found for HTTP request with URI [/PracticeJavaWeb/controller] in DispatcherServlet with name 'dispatcher'
Spring Docs saying:
It is also possible to have just one root context for single DispatcherServlet scenarios.
