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?
If I change server.contextPath
to server.contextPath=/api
and @RequestMapping
in my RestController to @RequestMapping("/users")
everything works fine. create()
method is being called with and without of trailing slash at the end on the URL.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.