I am facing an issue with my Spring Boot application where I have a single controller that handles POST requests only. I have set the context path in my application.yml
as server.servlet.context-path: /context/path
. The goal is to handle POST requests for both /context/path
and /context/path/
URLs.
My controller looks like this:
@RestController
@RequestMapping("")
public class MyController {
@PostMapping({ "", "/" })
public ResponseEntity<String> handlePostRequest() {
// Handling POST request logic
return ResponseEntity.ok("POST request handled");
}
}
When I send a POST request to /context/path
, it gets redirected with a 302 status code and the request method changes to GET, and it gets redirected to /context/path/
.
I have tried different combinations of @RequestMapping
and PostMapping
. Nothing worked.
I found some recommended solution to create a WebConfiguration and override the configurePathMatch method. But the methods like setUseTrailingSlashMatch
or setMatchOptionalTrailingSeparator
are deprecated.
Despite these attempts, the issue persists. How can I configure my application to handle the requests with or without trailing slashes? Any insights or suggestions on resolving this issue would be greatly appreciated.