2

I am working on a web project and using Spring MVC 3.1.1. Spring MVC is used to serve REST services (using URL annotations)

Regarding to my problem:

Let's say my url path for a service is as;

http://localhost:8080/MyAppName/services/meteo/queryWeatherData/lon/39.1123/lat/39.3123

And my controller method is as;

@RequestMapping(method = RequestMethod.GET, value = {"/queryWeatherData/lon/{lon}/lat/{lat}"})
    public void queryWeatherData(
            final @PathVariable("lon") float lon,
            final @PathVariable("lat") float lat,
            final HttpServletResponse response, final HttpServletRequest request) {
//
// DO STUFF and prepare response
//
}

I see that the second parameter (lat) is truncated after "." so I see that the value is 39.0 in server side.

I tried declaring a DefaultAnnotationHandlerMapping bean in my app-context.xml and set its useDefaultSuffixPattern to false but it did not work.

How can I solve this issue?

iso_9001_
  • 2,655
  • 6
  • 31
  • 47
  • Try putting a slash at the end i.e. `http://localhost:8080/MyAppName/services/meteo/queryWeatherData/lon/39.1123/lat/39.3123/`. If that changes it it maybe that it looks as `.3123` as file extension. – ced-b Sep 24 '13 at 13:39
  • Possible duplicate of http://stackoverflow.com/questions/3526523/spring-mvc-pathvariable-getting-truncated – M. Abbas Sep 24 '13 at 13:46
  • I am aware of the possible duplicate issue but the instructions on that one did not work for me – iso_9001_ Sep 24 '13 at 13:53

1 Answers1

2

Declaring the DefaultAnnotationHandlerMapping bean with useDefaultSuffixPattern=false is the right approach, but make sure you also comment out:

<mvc:annotation-driven />

See: How to change Spring MVC's behavior in handling url 'dot' character

Community
  • 1
  • 1
kevinpeterson
  • 1,150
  • 9
  • 15
  • I tried declaring the `DefaultAnnotationHandlerMapping` bean with `useDefaultSuffixPattern=false` but I didn't comment out `` and that was the case. Thank you very much – iso_9001_ Sep 24 '13 at 14:03