詳解配置spring-boot-actuator時候遇到的一些小問題
前言
spring-boot-actuator是一個spring-boot提供的用于監(jiān)控組件,只需要在代碼中加入依賴就可以了
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
遇到的一些小問題
1.可以加入依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
來保證actuator暴露接口的安全性,可以通過 -u 'user:password' 方式來訪問basic auth
2.如果項目依賴的是springmvc框架,并且基礎(chǔ)的配置文件是 application.yaml的話,可以增加 application.properties 文件來配置安全性的配置.
3.如果加入了security依賴,則所有的接口默認都需要被驗證,如果只想 /admin路徑下的請求進行驗證,則需要加入配置
security.basic.enabled=true security.basic.path=/admin security.user.name=admin security.user.password=password
4.如果項目依賴的是非springmvc框架的話, 需要在依賴中加入mvc的依賴
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency>
5.如果management.security.enabled的值是false的話,除開health接口還依賴endpoints.health.sensitive的配置外,其他接口都不需要輸入用戶名和密碼了。
6.actuator暴露的health接口權(quán)限是由兩個配置: management.security.enabled 和 endpoints.health.sensitive組合的結(jié)果進行返回的。
management.security.enabled | endpoints.health.sensitive | Unauthenticated | Authenticated |
false | false | Full content | Full content |
false | true | Status only | Full content |
true | false | Status only | Full content |
true | true | No content | Full content |
7.actuator組件里面除開上面提到的metrics和health接口以外,還有很多默認的其他接口,如果它默認的接口不能滿足你的需求的話,還可以通過繼承它的 AbstractEndpoint 類來實現(xiàn)自己的Endpoint
最后附加一個配置文件例子:
security.basic.enabled=true security.basic.path=/admin #針對/admin路徑進行認證 security.user.name=admin #認證使用的用戶名 security.user.password=password #認證使用的密碼 management.security.roles=SUPERUSER management.port=11111 #actuator暴露接口使用的端口,為了和api接口使用的端口進行分離 management.context-path=/admin #actuator暴露接口的前綴 management.security.enabled=true #actuator是否需要安全保證 endpoints.metrics.sensitive=false #actuator的metrics接口是否需要安全保證 endpoints.metrics.enabled=true endpoints.health.sensitive=false #actuator的health接口是否需要安全保證 endpoints.health.enabled=true
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解Mybatis內(nèi)的mapper方法為何不能重載
這篇文章主要介紹了詳解Mybatis內(nèi)的mapper方法為何不能重載,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12Java日期格式化的實現(xiàn)(@JsonFormat和@JSONField)
本文主要介紹了Java日期格式化的實現(xiàn),主要介紹了@JsonFormat和@JSONField兩種方式,具有一定的參考價值,感興趣的可以了解一下2024-05-05詳解Java中的println輸入和toString方法的重寫問題
這篇文章主要介紹了Java中的println輸入和toString方法的重寫,一個對象數(shù)組在調(diào)用Arrays.toString打印時,相當于遍歷數(shù)組,然后打印里邊每個對象,這再打印對象就調(diào)用對象自己的toString了,需要的朋友可以參考下2022-04-04Java設(shè)計模式之建造者模式(Builder模式)介紹
這篇文章主要介紹了Java設(shè)計模式之建造者模式(Builder模式)介紹,本文講解了為何使用建造者模式、如何使用建造者模式、Builder模式的應(yīng)用等內(nèi)容,需要的朋友可以參考下2015-03-03