|
此版本仍在开发中,尚未视为稳定版。如需最新稳定版本,请使用 Spring Boot 4.0.4! |
会话(sessions)
sessions 端点提供有关由 Spring Session 管理的应用程序 HTTP 会话的信息。
检索会话
要获取会话信息,请向 GET 发起一个 /actuator/sessions 请求,如下列基于 curl 的示例所示:
$ curl 'http://localhost:8080/actuator/sessions?username=alice' -i -X GET
前面的示例检索用户名为 alice 的用户的所有会话。
返回的响应类似于以下内容:
HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 789
{
"sessions" : [ {
"id" : "ad7b252a-7836-47d4-9d64-f642c28f8a02",
"attributeNames" : [ ],
"creationTime" : "2026-03-18T22:58:24.964796040Z",
"lastAccessedTime" : "2026-03-19T10:57:39.964802432Z",
"maxInactiveInterval" : 1800,
"expired" : false
}, {
"id" : "4db5efcc-99cb-4d05-a52c-b49acfbb7ea9",
"attributeNames" : [ ],
"creationTime" : "2026-03-19T05:58:24.966669375Z",
"lastAccessedTime" : "2026-03-19T10:57:47.966672140Z",
"maxInactiveInterval" : 1800,
"expired" : false
}, {
"id" : "569912a4-5ef4-4071-916f-507b7e8283f9",
"attributeNames" : [ ],
"creationTime" : "2026-03-19T08:58:24.966675346Z",
"lastAccessedTime" : "2026-03-19T10:58:12.966676168Z",
"maxInactiveInterval" : 1800,
"expired" : false
} ]
}
响应结构
响应包含匹配会话的详细信息。 下表描述了响应的结构:
| 路径 | 类型 | <description> </description> |
|---|---|---|
|
|
指定用户名的会话。 |
|
|
会话的ID。 |
|
|
存储在会话中的属性名称。 |
|
|
会话创建的时间戳。 |
|
|
会话最后一次被访问的时间戳。 |
|
|
会话在过期前允许的最长非活动时间(以秒为单位)。 |
|
|
会话是否已过期。 |
检索单个会话
要获取单个会话,请向 GET 发起一个 /actuator/sessions/{id} 请求,如下列基于 curl 的示例所示:
$ curl 'http://localhost:8080/actuator/sessions/4db5efcc-99cb-4d05-a52c-b49acfbb7ea9' -i -X GET
前面的示例检索了 id 为 4db5efcc-99cb-4d05-a52c-b49acfbb7ea9 的会话。
返回的响应类似于以下内容:
HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 208
{"id":"4db5efcc-99cb-4d05-a52c-b49acfbb7ea9","attributeNames":[],"creationTime":"2026-03-19T05:58:24.966669375Z","lastAccessedTime":"2026-03-19T10:57:47.966672140Z","maxInactiveInterval":1800,"expired":false}
删除会话
要删除一个会话,请向 DELETE 发送一个 /actuator/sessions/{id} 请求,如下列基于 curl 的示例所示:
$ curl 'http://localhost:8080/actuator/sessions/4db5efcc-99cb-4d05-a52c-b49acfbb7ea9' -i -X DELETE
前面的示例删除了 id 为 4db5efcc-99cb-4d05-a52c-b49acfbb7ea9 的会话。