spring監(jiān)視器actuator配置應(yīng)用
引入依賴
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>3.1.0</version>
</dependency>配置
# actuator # 將所有路徑都加入監(jiān)視 management.endpoints.web.exposure.include=* # 將某幾個(gè)路徑取消監(jiān)控 management.endpoints.web.exposure.exclude=info,caches
應(yīng)用
自帶的路徑
localhost:8080/mycommunity/actuator/health

自定義路徑
@Component
@Endpoint(id = "database")
public class DatabaseEndpoint {
private static final Logger logger = LoggerFactory.getLogger(DatabaseEndpoint.class);
@Autowired
private DataSource dataSource;
// readOperation means this method can only be accessed by get request
// writeOperation means this method can only be accessed by post request
@ReadOperation
public String checkConnection(){
try(
Connection connection = dataSource.getConnection();
) {
return CommunityUtil.getJSONString(0,"success");
} catch (SQLException e) {
e.printStackTrace();
logger.error("failed");
}
return CommunityUtil.getJSONString(1, "failed");
}
}訪問瀏覽器:localhost:8080/mycommunity/actuator/database

注意actuator路徑只能對管理員訪問,注意做權(quán)限管理
到此這篇關(guān)于spring監(jiān)視器actuator的文章就介紹到這了,更多相關(guān)spring監(jiān)視器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot實(shí)現(xiàn)發(fā)送郵件功能過程圖解
這篇文章主要介紹了SpringBoot實(shí)現(xiàn)發(fā)送郵件功能過程圖解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
springboot集成elasticsearch7的圖文方法
本文記錄springboot集成elasticsearch7的方法,本文通過圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),需要的朋友參考下吧2021-05-05
Mybatis Limit實(shí)現(xiàn)分頁功能
這篇文章主要介紹了Mybatis Limit實(shí)現(xiàn)分頁功能,使用Limit實(shí)現(xiàn)分頁可以減少數(shù)據(jù)的處理量,本文通過代碼講解的非常詳細(xì),需要的朋友可以參考下2021-04-04
使用Springboot實(shí)現(xiàn)OAuth服務(wù)的示例詳解
OAuth(Open Authorization)是一個(gè)開放標(biāo)準(zhǔn),用于授權(quán)第三方應(yīng)用程序訪問用戶資源,而不需要共享用戶憑證。本文主要介紹了如何使用Springboot實(shí)現(xiàn)一個(gè)OAuth服務(wù),需要的可以參考一下2023-05-05

