Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC on tomcat 7 gives HTTP 405 for requests without a path Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC on tomcat 7 gives HTTP 405 for requests without a path

    I'm having this issue with Spring MVC on Tomcat that causes the server to return Tomcat's 405 error after the controller method executes.

    Web.xml
    Code:
    <!-- Spring security configuration -->
      <context-param>
    	<param-name>contextConfigLocation</param-name>
    	<param-value>/WEB-INF/applicationContext-security.xml</param-value>
      </context-param>
      <filter>
     	<filter-name>springSecurityFilterChain</filter-name>
     	<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
      </filter>
      <filter-mapping>
     	<filter-name>springSecurityFilterChain</filter-name>
     	<url-pattern>/*</url-pattern>
      </filter-mapping>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!--  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>
    My controller uses
    Code:
    @RequestMapping(value = {"", "/*"}, method = RequestMethod.GET)
    Code:
    @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?

  • #2
    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.

    Code:
      <!-- Disables Servlet Container welcome file handling. Needed for compatibility with Servlet 3.0 and Tomcat 7.0 -->
      <welcome-file-list>
        <welcome-file></welcome-file>
      </welcome-file-list>

    Comment

    Working...
    X