I have exposed an api using springboot.
It accepts HTTP POST method. here is the code
@RequestMapping(value = "upload/config_data", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA)
public String uploadConfigData(@RequestParam("inFile") MultipartFile inFile,
@RequestParam("rowData") String rowData) throws ServiceException, DAOException {
return extConfigApiService.uploadConfigData(inFile, rowData);
}
in springboot 2.x I could call this endpoint with a trailing slash and it would work fine http://localhost:8000/upload/config_data/
I upgraded to springboot 3.1.4 and now when I call the same endpoint I get a 404 response.
When I remove the trailing "/" it is working.
Is there a way to make it work even with the trailing "/"?
Please help
>Solution :
In Spring Boot 2.x, trailing slashes were automatically ignored by default, allowing endpoints to be accessed with or without the trailing slash.
In Spring Boot 3.x you need to add a configuration to allow your trailing slashe
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseTrailingSlashMatch(true);
}
}
check documentation for more information :
https://www.baeldung.com/spring-boot-3-url-matching