Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following in Spring

@RequestMapping("/hello")

However Spring automatically adds mappings for /hello/ as well as /hello.*. How do I do an exact URL match?

Only /hello should work, anything else should 404

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
282 views
Welcome To Ask or Share your Answers For Others

1 Answer

Turning off suffix matching (useSuffixPatternMatch) on RequestMappingHandlerMapping will solve your problem, but doing so is actually not so easy, if you use <mvc:annotation-driven/> in your configuration (instead of manually wiring all the necessary infrastructure beans). In this case defining an additional bean of type RequestMappingHandlerMapping won't have any effect.

You have two options:

  1. Remove <mvc:annotation-driven/> expanding it to an equivalent set of bean definitions where you can apply the useSuffixPatternMatch setting.

  2. Keep <mvc:annotation-driven/> as it is, and use a much easier workaround described here: https://jira.springsource.org/browse/SPR-9371. This basically adds a BeanPostProcessor which retrieves the RequestMappingHandlerMapping bean created by the mvc namespace, and sets the above mentioned flag.

There is also another ticket requesting that it should be much easier to customize the RequestMappingHandlerMapping created by the mvc namespace without applying hacks like above. You can consider voting on this ticket.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...