跳到主要内容

会话 (sessions)

DeepSeek V3 中英对照 Sessions (sessions)

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

获取会话

要检索会话,请向 /actuator/sessions 发起 GET 请求,如下面的基于 curl 的示例所示:

$ curl 'http://localhost:8080/actuator/sessions?username=alice' -i -X GET
bash

前面的示例检索了用户名为 alice 的用户的所有会话。返回的响应类似于以下内容:

HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 789

{
"sessions" : [ {
"id" : "8dea6dc5-9738-499f-99a2-7ac19144b334",
"attributeNames" : [ ],
"creationTime" : "2025-01-22T23:07:04.850066495Z",
"lastAccessedTime" : "2025-01-23T11:06:19.850072736Z",
"maxInactiveInterval" : 1800,
"expired" : false
}, {
"id" : "9f9476f0-c3d8-4c87-bd34-a4f2a8d4244f",
"attributeNames" : [ ],
"creationTime" : "2025-01-23T09:07:04.850844758Z",
"lastAccessedTime" : "2025-01-23T11:06:52.850845389Z",
"maxInactiveInterval" : 1800,
"expired" : false
}, {
"id" : "4db5efcc-99cb-4d05-a52c-b49acfbb7ea9",
"attributeNames" : [ ],
"creationTime" : "2025-01-23T06:07:04.850839869Z",
"lastAccessedTime" : "2025-01-23T11:06:27.850842042Z",
"maxInactiveInterval" : 1800,
"expired" : false
} ]
}
http

查询参数

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

参数描述
username用户的名称。

响应结构

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

路径类型描述
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
bash

前面的示例获取了 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":"2025-01-23T06:07:04.850839869Z","lastAccessedTime":"2025-01-23T11:06:27.850842042Z","maxInactiveInterval":1800,"expired":false}
http

响应结构

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

路径类型描述
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
bash

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