I’m having this issue with Spring MVC on Tomcat that I think was the same one addressed in this post but they didn’t post the solution.
Web.xml
<!-- Spring MVC app -->
<servlet>
<servlet-name>client</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/client/client-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>client</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
client-servlet.xml
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />
<context:component-scan base-package="com.company.client.controllers" />
<!-- Enable an interceptor to set up the Trace objects for all Controller invocations -->
<mvc:interceptors>
<bean class="com.company.client.interceptor.TraceInterceptor"/>
</mvc:interceptors>
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/WEB-INF/client/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/client/views directory -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/client/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
I use a standard ContextLoaderInitializer.
My controller uses @RequestMapping(value = {"", "/*"}, method = RequestMethod.GET)
@RequestMapping(value = {"", "/*"}, method = RequestMethod.GET)
public String home(Model model) {
retrieveOffers(model);
logger.warning("Loading home page");
return "main";
}
When i visit mydomain.com or mydomain.com/ – I get the Tomcat 405 GET not supported error.
If I put anything in the trailing path it loads the page just fine. (e.g. mydomain.com/a)
The interesting thing is that I always see the “Loading home page” log statement and from my logs there is no difference between requests. It just seems like Tomcat is intercepting the response sometime between the controller finishing and the view rendering. Any thoughts?
there was a statement in the web.xml that somebody on my team had added. It intercepted response after the controller and redirected to a servlet that didn’t implement doget. Hopefully this save somebody some time later on. Use the following to ensure the default servlet container does not override spring.