Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring引导在上下文路径中重定向POST_Java_Spring Boot - Fatal编程技术网

Java Spring引导在上下文路径中重定向POST

Java Spring引导在上下文路径中重定向POST,java,spring-boot,Java,Spring Boot,当我在基本上下文路径中进行POST时,应用程序返回重定向(302),并且我得到一个错误 我的application.properties ... server.servlet.context-path=/api/v1/application ... 我的控制者 @RestController public class RestService { @PostMapping @ResponseStatus(HttpStatus.CREATED) public Respon

当我在基本上下文路径中进行POST时,应用程序返回重定向(302),并且我得到一个错误

我的
application.properties

...
server.servlet.context-path=/api/v1/application
...
我的控制者

@RestController
public class RestService {

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public ResponseDTO myMethod(@RequestBody RequestDTO requestDTO) {
        log.trace("m=myMethod");
        return service.insert(requestDTO);
    }

}
如果我在http://localhost:8080/api/v1/application 我得到一个302重定向到http://localhost:8080/api/v1/application/ 如果客户端遵循重定向,则应用程序返回405(方法不允许)

卷曲

C:\>curl-v-X POSThttp://localhost:8080/api/v1/customer
*正在尝试127.0.0.1。。。
*TCP_节点集
*已连接到本地主机(127.0.0.1)端口8080(#0)
>POST/api/v1/customer HTTP/1.1
>主机:本地主机:8080
>用户代理:curl/7.55.1
>接受:*/*
>
尝试更改为@PostMapping(“/”),其中有一个requestbody参数。。您使用postman访问api了吗?我已经尝试过了,但没有成功。请尝试更改为@PostMapping(“/”)有一个requestbody参数。。你是不是用邮递员找到了api?我已经试过了,但没用。
C:\>curl -v -X POST http://localhost:8080/api/v1/customer
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /api/v1/customer HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 302
< Location: http://localhost:8080/api/v1/customer/
< Transfer-Encoding: chunked
< Date: Mon, 31 Aug 2020 23:34:07 GMT
<
* Connection #0 to host localhost left intact