![](/img/trans.png)
[英]How to stop spring-boot embedded-undertow from adding trailing slash
[英]Spring-boot rest api. Truncate trailing slash
我有一個spring-boot
rest api。
在我的application.properties
我有:
server.port=8100
server.contextPath=/api/users
有一個控制器:
@RestController
@RequestMapping("")
public class UserService {
@RequestMapping(value = "", method = POST, produces = "application/json; charset=UTF-8")
public ResponseEntity<UserJson> create(@RequestBody UserJson userJson) {
...
}
}
當我打電話時:
POST http://localhost:8100/api/users/
注意尾部斜杠(帶有用戶的 json) - create
方法執行正常。
但是當我打電話時:
POST http://localhost:8100/api/users
不帶斜杠(使用用戶的 json) - 我收到405
錯誤:
{ "timestamp": 1520839904193, "status": 405, "error": "Method Not Allowed", "exception": "org.springframework.web.HttpRequestMethodNotSupportedException", "message": "Request method 'GET' not supported", "path": "/api/users/" }
我需要沒有斜杠的 URL,只是.../api/users
,為什么它被視為GET
方法?
如果我改變server.contextPath
到server.contextPath=/api
和@RequestMapping
在我RestController到@RequestMapping("/users")
一切工作正常。 在 URL 末尾使用和不使用尾隨斜杠調用create()
方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.