跳到主要内容
版本:3.5.10

Sessions (sessions)

QWen Max 中英对照 Sessions (sessions) Sessions (sessions)

sessions 端点提供有关由 Spring Session 管理的应用程序 HTTP 会话的信息。

检索会话

要检索会话,请向 /actuator/sessions 发起一个 GET 请求,如下列基于 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" : "4db5efcc-99cb-4d05-a52c-b49acfbb7ea9",
"attributeNames" : [ ],
"creationTime" : "2026-01-22T03:01:04.057997717Z",
"lastAccessedTime" : "2026-01-22T08:00:27.058000112Z",
"maxInactiveInterval" : 1800,
"expired" : false
}, {
"id" : "5869b9a7-6be7-4a09-a8ac-a1b186650aae",
"attributeNames" : [ ],
"creationTime" : "2026-01-21T20:01:04.057001614Z",
"lastAccessedTime" : "2026-01-22T08:00:19.057007986Z",
"maxInactiveInterval" : 1800,
"expired" : false
}, {
"id" : "a44c5e4a-e280-4a17-9673-1c75837eefcd",
"attributeNames" : [ ],
"creationTime" : "2026-01-22T06:01:04.058002937Z",
"lastAccessedTime" : "2026-01-22T08:00:52.058003528Z",
"maxInactiveInterval" : 1800,
"expired" : false
} ]
}

查询参数

该端点使用查询参数来限制其返回的会话。下表展示了唯一的必需查询参数:

ParameterDescription
username用户的名称。

响应结构

响应包含匹配会话的详细信息。下表描述了响应的结构:

路径(Path)类型(Type)描述(Description)
sessionsArray给定用户名的会话列表。
sessions.[].idString会话的 ID。
sessions.[].attributeNamesArray存储在会话中的属性名称列表。
sessions.[].creationTimeString会话创建的时间戳。
sessions.[].lastAccessedTimeString会话最后一次被访问的时间戳。
sessions.[].maxInactiveIntervalNumber会话在过期前允许的最大非活动时间(以秒为单位)。
sessions.[].expiredBoolean该会话是否已过期。

检索单个会话

要检索单个会话,请向 /actuator/sessions/{id} 发起一个 GET 请求,如下列基于 curl 的示例所示:

$ curl 'http://localhost:8080/actuator/sessions/4db5efcc-99cb-4d05-a52c-b49acfbb7ea9' -i -X GET

前面的示例检索了 id4db5efcc-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-01-22T03:01:04.057997717Z","lastAccessedTime":"2026-01-22T08:00:27.058000112Z","maxInactiveInterval":1800,"expired":false}

响应结构

响应包含所请求会话的详细信息。下表描述了响应的结构:

PathTypeDescription
idString会话的 ID。
attributeNamesArray存储在会话中的属性名称。
creationTimeString会话创建的时间戳。
lastAccessedTimeString会话最后一次被访问的时间戳。
maxInactiveIntervalNumber会话过期前允许的最大非活动时间(以秒为单位)。
expiredBoolean会话是否已过期。

删除会话

要删除一个会话,请向 /actuator/sessions/{id} 发起一个 DELETE 请求,如下列基于 curl 的示例所示:

$ curl 'http://localhost:8080/actuator/sessions/4db5efcc-99cb-4d05-a52c-b49acfbb7ea9' -i -X DELETE

前面的示例删除了 id4db5efcc-99cb-4d05-a52c-b49acfbb7ea9 的会话。