0
@RequestMapping(value = "/newLoadtest/{loadtest}", method = RequestMethod.POST)
public @ResponseBody void addNewLoadTest(@PathVariable("loadtest") String loadtest) {
        System.out.println(loadtest);
}

This is the code that I have written and if lets say the loadtest string is "test.version" . The period doesn't work for some reason. It prints out "test" only

I think the issue here might be encoding the url but i am not sure how to go about it. Please help

user3100209
  • 357
  • 1
  • 4
  • 17
  • Read http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-requestmapping-suffix-pattern-match – JB Nizet Sep 29 '15 at 16:18

2 Answers2

0

Its spring's smart way to avoid any suffix in URI. You have two ways to disable it.

add ":.+" after your path variable definition.

@RequestMapping(value = "/newLoadtest/{loadtest:.+}", method = RequestMethod.POST) 

Another way is to Use your own "DefaultAnnotationHandlerMapping" and disable "useDefaultSuffixPattern" to false.

Jags
  • 799
  • 7
  • 19
0

Check below quote from Spring reference:

By default Spring MVC automatically performs "." suffix pattern matching so that a controller mapped to /person is also implicitly mapped to /person.. This allows indicating content types via file extensions, e.g. /person.pdf, /person.xml, etc. A common pitfall however is when the last path segment of the mapping is a URI variable, e.g. /person/{id}. While a request for /person/1.json would correctly result in path variable id=1 and extension ".json", when the id naturally contains a dot, e.g. /person/joe@email.com the result does not match expectations. Clearly here ".com" is not a file extension.

if you do not want to use extension content negotiation you can disable it by this line in below code configurer.setUseSuffixPatternMatch(false); or I think the below solution is better to just use registered Suffix, it is up to your needs

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
    //configurer.setUseSuffixPatternMatch(false);//this will disable all suffices from negotiation
    configurer.setUseRegisteredSuffixPatternMatch(true);
}
}
Bassem Reda Zohdy
  • 12,662
  • 3
  • 33
  • 39