I have a spring-boot
rest api.
In my application.properties
I have:
server.port=8100
server.contextPath=/api/users
There's a controller:
@RestController
@RequestMapping("")
public class UserService {
@RequestMapping(value = "", method = POST, produces = "application/json; charset=UTF-8")
public ResponseEntity<UserJson> create(@RequestBody UserJson userJson) {
...
}
}
When I call:
POST http://localhost:8100/api/users/
notice the trailing slash (with user's json) - create
method executes fine.
But when I call:
POST http://localhost:8100/api/users
without trailing slash (with user's json) - I receive 405
error:
{ "timestamp": 1520839904193, "status": 405, "error": "Method Not Allowed", "exception": "org.springframework.web.HttpRequestMethodNotSupportedException", "message": "Request method 'GET' not supported", "path": "/api/users/" }
I need my URL without trailing slash, just .../api/users
, and why it's being treated as GET
method?