0

In my spring mvc context I have the following mappings (there is much more but this will give a general idea). <mvc:view-controller path="/echo" view-name="echo"/>

<context:component-scan base-package="com.myapp.controllers"/>

The issue I am running into is that I have an annotated controller with @RequestMapping(value = "/e{number}". In the same controller with the request mapping I have a redirect the dumps the user to "home" if the @PathVariable is not a integer.

However I do not want them to be dumped to home if they are matching the path/echo. I tried setting a <property name="order" value="0" /> on the view resolve however, without a order on the context, that is still taking priority.

How can I set priority on my component scan, or force the view-resolver to be matched first before the annotated controllers.

zmanc
  • 5,201
  • 12
  • 45
  • 90
  • 1
    Having the view resolver in front of the controllers sounds like a terrible idea (if it's able to be done), particularly since the UrlBasedViewResolver (or something) and subclasses throw exceptions if they don't find a match rather than passing through the chain. If you only want the controller to step in when the path variable is an integer you should use the pattern matching option for the RequestMapping, something like `/e{number:\d+}` should steer you in the right direction for a Google search. – Matt Whipple Aug 24 '13 at 01:54
  • I tried ` @RequestMapping(value = "/e{number:\\d+}"` and `@RequestMapping(value = "/e{^\\+?\\d+\$}"` but neither worked. I am going to keep trying and see what I can find. – zmanc Aug 24 '13 at 02:11
  • I tried `@RequestMapping(value = "/{^\\e+?\\d+\$}"` and I get a 400 error saying `The request sent by the client was syntactically incorrect.` – zmanc Aug 24 '13 at 02:26
  • I asked a different question for the mapping with the regex. http://stackoverflow.com/questions/18422368/regex-in-spring-controller – zmanc Aug 24 '13 at 19:36
  • @MattWhipple, submit your comment as an answer please so I can mark it as correct. I misunderstood your comment when you had {number:\d+} because I was sanitizing my code I swapped my actual var name for number, and didn't realize that was what you were mentioning. I asked another question at http://stackoverflow.com/questions/18422368/regex-in-spring-controller/18422504 and that cleared it up for me. Thank you again! – zmanc Aug 25 '13 at 01:43

1 Answers1

1

Having the view resolver in front of the controllers sounds like a terrible idea (if it's able to be done), particularly since the UrlBasedViewResolver (or something) and subclasses throw exceptions if they don't find a match rather than passing through the chain. If you only want the controller to step in when the path variable is an integer you should use the pattern matching option for the RequestMapping, something like /e{number:\d+} should steer you in the right direction for a Google search.

Matt Whipple
  • 7,034
  • 1
  • 23
  • 34