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.

5
  • 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. Commented Aug 24, 2013 at 1: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. Commented Aug 24, 2013 at 2:11
  • I tried @RequestMapping(value = "/{^\\e+?\\d+\$}" and I get a 400 error saying The request sent by the client was syntactically incorrect. Commented Aug 24, 2013 at 2:26
  • I asked a different question for the mapping with the regex. stackoverflow.com/questions/18422368/regex-in-spring-controller Commented Aug 24, 2013 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 stackoverflow.com/questions/18422368/regex-in-spring-controller/… and that cleared it up for me. Thank you again! Commented Aug 25, 2013 at 1:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.