springboot服务器端默认60秒超时的解决方法

遇到后台接口处理比较慢,前端总是报错超时的情况。

感觉是默认60秒就超时了。

解决方法:

1.后台配置文件增加参数:

server:
  tomcat:
    keep-alive-timeout: 120000
  port: 9000

设置为120秒才超时。

2.前端请求增加参数:

        getQuestionAnswer(reqJson) {
            
            this.$axios.post("/api/questionAnswer", reqJson, {
                headers: {
                    "Content-Type": "application/json",
                },
                timeout: 120000
                })
                .then((res) => {
                console.log("返回200。");
                //响应体在data里,answer是json的key,后台设置的
                this.deal(res.data.answer)

                })
                .catch((err) => {
                //注意,201也会被当成错误catch到;只有200才不是错误
                console.log("返回err。"+err);
                });

        },

注意timeout不在header里,在header旁边。

你可能感兴趣的:(spring,boot,后端,java)