会话(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" : "d0f4ebfd-53f3-4ac2-b155-393bec4223fe",
    "attributeNames" : [ ],
    "creationTime" : "2025-05-26T01:08:26.382283Z",
    "lastAccessedTime" : "2025-05-26T03:08:14.382283Z",
    "maxInactiveInterval" : 1800,
    "expired" : false
  }, {
    "id" : "e7e4cede-4863-45d0-8572-3790843e8b49",
    "attributeNames" : [ ],
    "creationTime" : "2025-05-25T15:08:26.381431Z",
    "lastAccessedTime" : "2025-05-26T03:07:41.381433Z",
    "maxInactiveInterval" : 1800,
    "expired" : false
  }, {
    "id" : "4db5efcc-99cb-4d05-a52c-b49acfbb7ea9",
    "attributeNames" : [ ],
    "creationTime" : "2025-05-25T22:08:26.382281Z",
    "lastAccessedTime" : "2025-05-26T03:07:49.382282Z",
    "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-25T22:08:26.382281Z","lastAccessedTime":"2025-05-26T03:07:49.382282Z","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 的会话。