spring監(jiān)視器actuator配置應用
更新時間:2023年07月08日 09:31:56 作者:back2childhood
這篇文章主要介紹了spring監(jiān)視器actuator配置應用,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
引入依賴
<!-- 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=* # 將某幾個路徑取消監(jiān)控 management.endpoints.web.exposure.exclude=info,caches
應用
自帶的路徑
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路徑只能對管理員訪問,注意做權限管理
到此這篇關于spring監(jiān)視器actuator的文章就介紹到這了,更多相關spring監(jiān)視器內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
SpringBoot實現(xiàn)發(fā)送郵件功能過程圖解
這篇文章主要介紹了SpringBoot實現(xiàn)發(fā)送郵件功能過程圖解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-03-03springboot集成elasticsearch7的圖文方法
本文記錄springboot集成elasticsearch7的方法,本文通過圖文實例代碼相結合給大家介紹的非常詳細,需要的朋友參考下吧2021-05-05使用Springboot實現(xiàn)OAuth服務的示例詳解
OAuth(Open Authorization)是一個開放標準,用于授權第三方應用程序訪問用戶資源,而不需要共享用戶憑證。本文主要介紹了如何使用Springboot實現(xiàn)一個OAuth服務,需要的可以參考一下2023-05-05