2

I am using Spring MVC 3.2 and deploying in Apache Tomcat 1.7x. My login url is /web/login but using url /web/login.abc where abc can be any text including space.

In both cases it is returning the same resource which I will like to avoid and return HTTP code 404.

Tried adding the below in web.xml but it did not help

`<beans:bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <beans:property name="useDefaultSuffixPattern" value="false" />
</beans:bean>`
ad-inf
  • 1,520
  • 4
  • 30
  • 53

1 Answers1

4

This config depends on the version you're using which you've omitted in your question. Since Spring 4.0.3 the suffix properties are set on the PathMatchConfigurer class. As per Spring doc the config should be under mvc:annotation-driven, e.g.

  <mvc:annotation-driven>
    <mvc:path-matching suffix-pattern="false" />
  </mvc:annotation-driven>

as explained in the docs

Whether to use suffix pattern match (".*") when matching patterns to requests. If enabled a method mapped to "/users" also matches to "/users.*". The default value is true.

For Spring 3.2 it should be

  <beans:bean id="handlerMapping"
 class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
      <beans:property name="useSuffixPatternMatch" value="false"/>
  </beans:bean>`

Also, if you're using the mvc:annotation-driven element in your config, take a note of Biju's answer from this question How do I restrict route extensions in @RequestMapping paths for Spring MVC controllers?

Community
  • 1
  • 1
Master Slave
  • 27,771
  • 4
  • 57
  • 55
  • thanks for your response. I should have clarified this in my post, we are using spring 3.2 as of now. Any suggestion on Spring 3.2 version? – ad-inf Jun 03 '15 at 05:03
  • I've added for Spring 3.2, but its from the top of my head. I'll try to verify this later, but it should be correct, let me know if its working for you. – Master Slave Jun 03 '15 at 05:12