1
votes

I have a problem while use Spring MVC:

I wrote a Controller, a method named

@RequestMapping("/{moduleName}/{subModuleName}")
public ModelAndView getModuleContent(@PathVariable String moduleName, @PathVariable String subModuleName) {
     ...
}
,

now the problem is, when I access a static resource, for example:

http://www.mytomcat:8080/images/testpng


it would mapping that controller, but I don't want this, how can I resolve the conflict?

3

3 Answers

0
votes

configure following accordingly.

<mvc:resources mapping="/resources/**" location="/public-resources/"/>
1
votes

Try to specify regex pattern for path vars:

@RequestMapping(value = "/{year:\\d+}/{month:\\d+}/**", method = RequestMethod.GET)

This helps spring to avoid conflicts with <mvc:resources/> mapped to path like /images/**. If your path variable can contain all except 'images' you can try regex like this: (?!images).

0
votes

You may configure resource handlers for resource folders such as /images.

It should help, because mapping of these handlers would be more specific than /{moduleName}/{subModuleName}, therefore resource handlers should take precedence.