會話 (sessions)

sessions 端點提供了由 Spring Session 管理的應用程式 HTTP 會話資訊。

檢索會話

要檢索會話,請向 /actuator/sessions 傳送 GET 請求,如以下基於 curl 的示例所示

$ curl 'https://: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" : [ {
    "attributeNames" : [ ],
    "creationTime" : "2025-11-20T14:33:59.914866807Z",
    "expired" : false,
    "id" : "40b429f0-57dd-4aeb-a5ad-241bea75fcb7",
    "lastAccessedTime" : "2025-11-20T16:33:47.914867419Z",
    "maxInactiveInterval" : 1800
  }, {
    "attributeNames" : [ ],
    "creationTime" : "2025-11-20T04:33:59.914198661Z",
    "expired" : false,
    "id" : "13bd41f7-d039-4969-87bf-298833e7d86d",
    "lastAccessedTime" : "2025-11-20T16:33:14.914204682Z",
    "maxInactiveInterval" : 1800
  }, {
    "attributeNames" : [ ],
    "creationTime" : "2025-11-20T11:33:59.914862470Z",
    "expired" : false,
    "id" : "4db5efcc-99cb-4d05-a52c-b49acfbb7ea9",
    "lastAccessedTime" : "2025-11-20T16:33:22.914864303Z",
    "maxInactiveInterval" : 1800
  } ]
}

查詢引數

該端點使用查詢引數來限制其返回的會話。下表顯示了唯一必需的查詢引數

引數 描述

username

使用者的名稱。

響應結構

響應包含匹配會話的詳細資訊。下表描述了響應的結構

路徑 型別 描述

sessions

陣列

給定使用者名稱的會話。

sessions.[].id

字串

會話 ID。

sessions.[].attributeNames

陣列

儲存在會話中的屬性名稱。

sessions.[].creationTime

字串

會話建立的時間戳。

sessions.[].lastAccessedTime

字串

會話上次訪問的時間戳。

sessions.[].maxInactiveInterval

數字

會話過期前的最大允許非活動時間,單位為秒。

sessions.[].expired

布林值

會話是否已過期。

檢索單個會話

要檢索單個會話,請向 /actuator/sessions/{id} 傳送 GET 請求,如以下基於 curl 的示例所示

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

前面的示例檢索了 ID 為 4db5efcc-99cb-4d05-a52c-b49acfbb7ea9 的會話。結果響應類似於以下內容

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

{"attributeNames":[],"creationTime":"2025-11-20T11:33:59.914862470Z","expired":false,"id":"4db5efcc-99cb-4d05-a52c-b49acfbb7ea9","lastAccessedTime":"2025-11-20T16:33:22.914864303Z","maxInactiveInterval":1800}

響應結構

響應包含請求會話的詳細資訊。下表描述了響應的結構

路徑 型別 描述

id

字串

會話 ID。

attributeNames

陣列

儲存在會話中的屬性名稱。

creationTime

字串

會話建立的時間戳。

lastAccessedTime

字串

會話上次訪問的時間戳。

maxInactiveInterval

數字

會話過期前的最大允許非活動時間,單位為秒。

expired

布林值

會話是否已過期。

刪除會話

要刪除會話,請向 /actuator/sessions/{id} 傳送 DELETE 請求,如以下基於 curl 的示例所示

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

前面的示例刪除了 ID 為 4db5efcc-99cb-4d05-a52c-b49acfbb7ea9 的會話。

© . This site is unofficial and not affiliated with VMware.