会话 (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: 771

{
  "sessions" : [ {
    "id" : "be6ca414-c473-4234-bdaa-30ec05354cfc",
    "attributeNames" : [ ],
    "creationTime" : "2025-05-25T08:03:22.050264Z",
    "lastAccessedTime" : "2025-05-25T10:03:10.050264Z",
    "maxInactiveInterval" : 1800,
    "expired" : false
  }, {
    "id" : "37de89a7-eb68-4b92-8d17-9c5f3a1230b5",
    "attributeNames" : [ ],
    "creationTime" : "2025-05-24T22:03:22.049451Z",
    "lastAccessedTime" : "2025-05-25T10:02:37.049457Z",
    "maxInactiveInterval" : 1800,
    "expired" : false
  }, {
    "id" : "4db5efcc-99cb-4d05-a52c-b49acfbb7ea9",
    "attributeNames" : [ ],
    "creationTime" : "2025-05-25T05:03:22.050261Z",
    "lastAccessedTime" : "2025-05-25T10:02:45.050263Z",
    "maxInactiveInterval" : 1800,
    "expired" : false
  } ]
}

查询参数

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

Parameter Description

username

Name of the user.

响应结构

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

Path Type Description

sessions

Array

Sessions for the given username.

sessions.[].id

String

ID of the session.

sessions.[].attributeNames

Array

Names of the attributes stored in the session.

sessions.[].creationTime

String

Timestamp of when the session was created.

sessions.[].lastAccessedTime

String

Timestamp of when the session was last accessed.

sessions.[].maxInactiveInterval

Number

Maximum permitted period of inactivity, in seconds, before the session will expire.

sessions.[].expired

Boolean

Whether the session has expired.

获取单个会话

要获取单个会话,向 /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: 202

{"id":"4db5efcc-99cb-4d05-a52c-b49acfbb7ea9","attributeNames":[],"creationTime":"2025-05-25T05:03:22.050261Z","lastAccessedTime":"2025-05-25T10:02:45.050263Z","maxInactiveInterval":1800,"expired":false}

响应结构

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

Path Type Description

id

String

ID of the session.

attributeNames

Array

Names of the attributes stored in the session.

creationTime

String

Timestamp of when the session was created.

lastAccessedTime

String

Timestamp of when the session was last accessed.

maxInactiveInterval

Number

Maximum permitted period of inactivity, in seconds, before the session will expire.

expired

Boolean

Whether the session has expired.

删除会话

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

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

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