Spring - Spring Boot - Actuator Web 訪問開啟


1. 概述

  1. 打開 Spring Boot Actuator 的 Web 訪問

2. 場景

  1. 之前看 Spring 的時候, 曾經想了解當時的配置
  2. 后來發現, 確實有這么個工具
  3. 剛開始發現, 除了 actuator, 別的也看不了什么

3. 環境

  1. os

    1. win10
  2. jdk

    1. 1.8
  3. ide

    1. ida 2018.1
  4. spring

    1. spring boot
      1. 2.0.4 release
    2. 組件
      1. thymeleaf
      2. starter-web
      3. devtool
      4. starter-test
      5. actuator
  5. browser

    1. firefox
      1. 70.0
  6. ref

    1. spring boot in action

4. 問題

  1. 參考書

    1. ref

      1. spring boot in action
    2. 書上說

      1. 書上列了一堆 url
        1. 感覺可以看很多事
  2. 問題

    1. 我試了一圈, 就 3 個 url 能用
      1. \actuator
      2. \health
      3. \info
  3. 但是書上給我的感覺, 好像都是配上就好了

    1. 也不知道為啥
    2. 又要開始找開關

5. 解決

  1. 嘗試找 官方文檔

    1. 找到了 api

      1. ref
        1. Spring Boot Actuator: Production-ready features
    2. 看到了 清一色的 Yes

      1. 我陷入了沉思
        1. 為啥我就臉黑老是
  2. 再往下看

    1. 發現了另一個表格

      1. 發現 yes 的都是 jmx
      2. 而 web 那塊, 又都是 清一色的 no
    2. 好了, 確認是配置沒開

      1. 那到底怎么打開呢

6. 開關

  1. 配置

    management.endpoints.web.exposure.include=*
    
  2. 重啟

  3. 結果

    1. 管理 url 都可以訪問了

7. 其他

  1. actuator 的訪問方式

    1. jmx
    2. web
  2. enable 和 expose

    1. 概述

      1. 這倆概念, 我一開始搞混了
    2. enable

      1. 解釋
        1. 開啟
          1. 開啟, 是 jmx 和 web 訪問的前提
    3. expose

      1. 解釋
        1. 暴露
          1. 需要開啟
          2. 只有暴露對應方式, 才可以訪問
      2. exclude 和 include
        1. exclude
          1. 排除特定的 url
        2. include
          1. 開啟特定的 url
  3. 配置

    1. 默認配置

      # 結合官方文檔上面的表格, jmx 確實全開, web 確實只開了 info 和 health
      management.endpoints.jmx.exposure.exclude=* 
      management.endpoints.jmx.exposure.include=* 
      management.endpoints.web.exposure.exclude=* 
      management.endpoints.web.exposure.include=info, health
      
    2. 配置

      1. 思路
        1. 文檔上解釋的, 是 exclude 優先
        2. 但是實際上看起來, 是 后面的配置, 會覆蓋前面的配置
      2. 具體的配置, 我也不細說了

ps

  1. ref

    1. Spring Boot & Actuator
  2. 其他

    1. 感覺這玩意, 功能還很多, 以后可以仔細學學


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM