Bill Gorder wrote:Yup you can not have optional path parameters. If you do it the way you are trying to you will have to have two separate handler methods like you do now that call the same service, one would pass in the locale. What I was trying to tell you is you are going against the standard. How many sites have you visited that have locales as part of the URL path? Rather than going against the grain pick one of the accepted approaches for doing this sort of thing like what was specified in the link I gave. If you are set on URL based Locale negotiation than use option 4 and set it as a request parameter instead.
Bill Gorder wrote:
1) have the 2 controller methods for every one like you do now
2) Create a custom MethodArgumentResolver that works the same way as @PathVariable but accepts optional parameters, and defaults to en when not present. You could model this after theirs and register it in your configuration. You would create a new annotation like @OptionalPathParameter and use it instead of @PathVariable.
3)Since you have a session param for your locale you maybe don't care what the path param is so maybe something like this would work
3.- Is not valid either, as I don't want anyone acceding the application typing myapp/"whatever"/home, I need to validate that the url only contains the language identifiers I will deal with.