对于最新的稳定版本,请使用 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" : "6c189c2c-0a98-4510-909d-daec191759de",
"attributeNames" : [ ],
"creationTime" : "2025-08-20T18:38:26.791702915Z",
"lastAccessedTime" : "2025-08-21T06:37:41.791708435Z",
"maxInactiveInterval" : 1800,
"expired" : false
}, {
"id" : "9710920a-728e-4f59-9bb6-5bedd3c76d2f",
"attributeNames" : [ ],
"creationTime" : "2025-08-21T04:38:26.796578024Z",
"lastAccessedTime" : "2025-08-21T06:38:14.796578775Z",
"maxInactiveInterval" : 1800,
"expired" : false
}, {
"id" : "4db5efcc-99cb-4d05-a52c-b49acfbb7ea9",
"attributeNames" : [ ],
"creationTime" : "2025-08-21T01:38:26.796572974Z",
"lastAccessedTime" : "2025-08-21T06:37:49.796575709Z",
"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-21T01:38:26.796572974Z","lastAccessedTime":"2025-08-21T06:37:49.796575709Z","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
.