此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Boot 3.4.3

会话 (sessions)

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

检索会话

要检索会话,请创建一个GETrequest 添加到/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" : "c689ae43-9b6f-464d-bf02-fd46750726a5",
    "attributeNames" : [ ],
    "creationTime" : "2025-02-20T17:02:00.326793820Z",
    "lastAccessedTime" : "2025-02-20T19:01:48.326794661Z",
    "maxInactiveInterval" : 1800,
    "expired" : false
  }, {
    "id" : "4db5efcc-99cb-4d05-a52c-b49acfbb7ea9",
    "attributeNames" : [ ],
    "creationTime" : "2025-02-20T14:02:00.326788970Z",
    "lastAccessedTime" : "2025-02-20T19:01:23.326791155Z",
    "maxInactiveInterval" : 1800,
    "expired" : false
  }, {
    "id" : "b41a9263-f0d6-47f7-99cd-df817e2ca397",
    "attributeNames" : [ ],
    "creationTime" : "2025-02-20T07:02:00.325922087Z",
    "lastAccessedTime" : "2025-02-20T19:01:15.325929060Z",
    "maxInactiveInterval" : 1800,
    "expired" : false
  } ]
}

查询参数

终端节点使用查询参数来限制它返回的会话。 下表显示了单个必需的查询参数:

参数 描述

username

用户的名称。

响应结构

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

路径 类型 描述

sessions

Array

给定用户名的会话。

sessions.[].id

String

会话的 ID。

sessions.[].attributeNames

Array

会话中存储的属性的名称。

sessions.[].creationTime

String

创建会话时的时间戳。

sessions.[].lastAccessedTime

String

上次访问会话时的时间戳。

sessions.[].maxInactiveInterval

Number

会话过期前允许的最长非活动时间(以秒为单位)。

sessions.[].expired

Boolean

会话是否已过期。

检索单个会话

要检索单个会话,请创建一个GETrequest 添加到/actuator/sessions/{id},如以下基于 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":"2025-02-20T14:02:00.326788970Z","lastAccessedTime":"2025-02-20T19:01:23.326791155Z","maxInactiveInterval":1800,"expired":false}

响应结构

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

路径 类型 描述

id

String

会话的 ID。

attributeNames

Array

会话中存储的属性的名称。

creationTime

String

创建会话时的时间戳。

lastAccessedTime

String

上次访问会话时的时间戳。

maxInactiveInterval

Number

会话过期前允许的最长非活动时间(以秒为单位)。

expired

Boolean

会话是否已过期。

删除会话

要删除会话,请创建一个DELETErequest 添加到/actuator/sessions/{id},如以下基于 curl 的示例所示:

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

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


APP信息