server.servlet.session.timeout在Boot 2.1.4中不生效。

时间:2019-04-10 03:28:23

标签: spring-boot

我正在尝试使用server.servlet.session.timeout属性,但是超时似乎不起作用。我已经设置了一个简单的启动应用程序:

application.properties

server.port=9595
server.servlet.session.timeout=60s
# Also tried server.servlet.session.timeout=1m
# Also tried to combine with server.servlet.session.cookie.max-age=60s

典型的SpringBoot配置:

@SpringBootApplication
public class SessionTimeoutDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SessionTimeoutDemoApplication.class, args);
    }

}

和一个简单的控制器:

@RestController
public class SomeControler {


    @PostMapping(value = "/data") 
    public ResponseEntity<String> postData(@RequestBody String body) throws InterruptedException {
        Thread.sleep(300*1000); //wait 5 minutes
        return ResponseEntity.accepted().build();
    }
}

然后尝试:

date; curl -d "This is the data" -H "Content-Type: application/json" -X POST http://localhost:9595/data; date

该应用实际上等待5分钟,而不是按预期1分钟后超时

**Wed Apr 10 12:59:17 AEST 2019**
* About to connect() to localhost port 9595 (#0)
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9595 (#0)
> POST /data HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:9595
> Accept: */*
> Content-Type: application/json
> Content-Length: 16
> 
* upload completely sent off: 16 out of 16 bytes
< HTTP/1.1 202 
< Content-Length: 0
< Date: Wed, 10 Apr 2019 03:04:17 GMT
< 
* Connection #0 to host localhost left intact
**Wed Apr 10 13:04:17 AEST 2019**

任何人都可以看到我所缺少的东西吗?

谢谢。

0 个答案:

没有答案