此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Boot 3.5.5! |
会话 (sessions
)
这sessions
endpoint 提供有关由 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" : "0f862746-dae2-4b79-bd91-770298a9f261",
"attributeNames" : [ ],
"creationTime" : "2025-08-21T12:24:16.216473719Z",
"lastAccessedTime" : "2025-08-21T14:24:04.216474640Z",
"maxInactiveInterval" : 1800,
"expired" : false
}, {
"id" : "9254c2e8-82d4-4aff-bd9b-b84fcda48e66",
"attributeNames" : [ ],
"creationTime" : "2025-08-21T02:24:16.209423844Z",
"lastAccessedTime" : "2025-08-21T14:23:31.209429284Z",
"maxInactiveInterval" : 1800,
"expired" : false
}, {
"id" : "4db5efcc-99cb-4d05-a52c-b49acfbb7ea9",
"attributeNames" : [ ],
"creationTime" : "2025-08-21T09:24:16.216464030Z",
"lastAccessedTime" : "2025-08-21T14:23:39.216467868Z",
"maxInactiveInterval" : 1800,
"expired" : false
} ]
}
响应结构
响应包含匹配会话的详细信息。 下表描述了响应的结构:
路径 | 类型 | 描述 |
---|---|---|
|
|
给定用户名的会话。 |
|
|
会话的 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":"2025-08-21T09:24:16.216464030Z","lastAccessedTime":"2025-08-21T14:23:39.216467868Z","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
.