Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get 404 when i call api endpoint with a trailing "/" in springboot 3

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading