Spring Boot: avoiding PathVariable parameters getting truncated on dots
Using the @PathVariable
on a Spring Boot controller, if a value contains a dot (‘.’) the value after the dot will be truncated. This happen since Spring MVC considers anything after the last dot as a file extension by default.
In order to avoid to getting truncated values it can be disabled this Spring MVC “feature” setting to false
the useSuffixPatternMatch
option through the PathMatchConfigurer
:
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(false);
}
}
This configuration works for me with Spring Boot 1.2.2.
References
https://stackoverflow.com/questions/16332092/spring-mvc-pathvariable-with-dot-is-getting-truncated
https://stackoverflow.com/questions/3526523/spring-mvc-pathvariable-getting-truncated
https://github.com/spring-projects/spring-boot/issues/401
https://thecruskit.com/spring-pathvariable-and-truncation-after-dot-period/
-
The Venerable Reverend
-
infoj