Springboot入门之集成Actuator
创始人
2025-05-30 22:12:56
0

1.Actuator是什么?

Actuator是spring boot下的一个模块,提供http (或JMX)端点来实现对应用程序的监视和管理、收集运行状况等功能。

2.简单集成 添加相关依赖

        org.springframework.bootspring-boot-starter-actuator

3.启动测试

http://localhost:8080/actuator

默认开放3个endpoint, /actuator /actuator/health /actuator/health/{*path}

4.开放所有endpoint 修改application.yml

management:server:port: 12345             # 端口默认=server.port 增加安全性endpoints:web:exposure:include: "*"        # 开放节点 * 开放所有 beans,.....# exclude: beans    # 禁止开放节点 * 禁止开放所有 beans,.....base-path: /control   # 自定义根路径  增加安全性endpoint:shutdown:enabled: true         # 打开shutdown端点 POST请求health:show-details: always  # 获得健康检查中所有指标的详细信息beans:cache:time-to-live: 100s  # 不带参数的端点请求会自动进行缓存#health:#defaults:#enabled: false       # 禁用所有自动健康检查#mongo:#enabled: false       # 禁用制定组件(mongo)自动健康检查
{"_links": {"self": {"href": "http://localhost/actuator","templated": false},"beans": {"href": "http://localhost/actuator/beans","templated": false},"caches-cache": {"href": "http://localhost/actuator/caches/{cache}","templated": true},"caches": {"href": "http://localhost/actuator/caches","templated": false},"health": {"href": "http://localhost/actuator/health","templated": false},"health-path": {"href": "http://localhost/actuator/health/{*path}","templated": true},"info": {"href": "http://localhost/actuator/info","templated": false},"conditions": {"href": "http://localhost/actuator/conditions","templated": false},"configprops": {"href": "http://localhost/actuator/configprops","templated": false},"configprops-prefix": {"href": "http://localhost/actuator/configprops/{prefix}","templated": true},"env": {"href": "http://localhost/actuator/env","templated": false},"env-toMatch": {"href": "http://localhost/actuator/env/{toMatch}","templated": true},"loggers": {"href": "http://localhost/actuator/loggers","templated": false},"loggers-name": {"href": "http://localhost/actuator/loggers/{name}","templated": true},"heapdump": {"href": "http://localhost/actuator/heapdump","templated": false},"threaddump": {"href": "http://localhost/actuator/threaddump","templated": false},"metrics-requiredMetricName": {"href": "http://localhost/actuator/metrics/{requiredMetricName}","templated": true},"metrics": {"href": "http://localhost/actuator/metrics","templated": false},"scheduledtasks": {"href": "http://localhost/actuator/scheduledtasks","templated": false},"mappings": {"href": "http://localhost/actuator/mappings","templated": false}}
}

5.各个endpoint 介绍
5.1)beans:注册到Sprng容器中的Bean对象集合
5.2)caches:缓存信息
5.3)health:应用的健康状态
5.4)info:应用的基本信息,需要手工配置
5.5)conditions:自动配置生效的条件
5.6)configprops:获取所有的配置属性
5.7)auditevents:显示应用暴露的审计事件 
5.8)metrics:应用多样的度量信息                          查看某项的度量信息/metric/jvm.buffer.count
5.9)loggers:日志配置                                            loggers/root
5.10)httptrace:HTTP足迹,显示最近100个HTTP request/repsponse
5.11)env:当前的环境特性
5.12)flyway:显示数据库迁移路径的详细信息
5.13)shutdown:关闭应用                                        唯一POST请求的节点
5.14)mappings:所有的@RequestMapping路径
5.15)scheduledtask:应用中的调度任务
5.16)threaddump:线程信息
5.17)heapdump:JVM堆dump

6.端点保护

6.1添加依赖

       org.springframework.bootspring-boot-starter-security

6.2添加配置

spring:security:user:name: adminpassword: adminroles: admin

6.3配置拦截地址

package com.example.hellospringboot.config;import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.boot.actuate.context.ShutdownEndpoint;
import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;@Configuration
public class ActuatorSecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().requestMatchers(EndpointRequest.to(ShutdownEndpoint.class)).hasRole("admin").requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll().requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll().antMatchers("/control*").permitAll().antMatchers("/control**").authenticated().and().httpBasic();}
}

Springboot入门之简单启动_Ocean@上源码的博客-CSDN博客

相关内容

热门资讯

国医战士:我的觉醒之路与薪火守... 一、根脉:红土地上的传承之子 1974年,李铭豪出生在广东吴川一个淳朴的农家。这片南海之滨的红土地,...
库克预告:苹果今年有前所未见的... 1月31日消息,苹果日前交上了一份历史最强季度财报,多项核心财务指标创历史新高,iPhone业务成为...
原创 白... 一夜之间,全崩了 昨天白天的时候,看到白银和黄金在大跌,想想昨夜跌跌就差不多了,结果一觉醒来完全颠覆...
夜“血洗”!白银,史诗级暴跌!... 北京时间1月31日凌晨,现货白银价格一度暴跌36%,创出历史最大日内跌幅;现货黄金价格一度下跌超过1...
一老人家中发生火灾,近40万元... 前不久,自贡赵女士爷爷家发生了火灾。因为爷爷奶奶不喜欢把钱存银行,家里近40万现金被烧毁大半。赵女士...
史诗级暴跌!白银一度重挫18% 1月30日,此前连续暴涨的贵金属,集体踩下“急刹”,其中白银等品种更迎来史诗级暴跌。 国际市场上现货...
视频|黄金白银“瀑布流直线跳水... 1月29日至1月30日,黄金白银遭遇“瀑布流直线跳水”,现货黄金从猛冲5600美元/盎司,到跌穿50...
今天凌晨,黄金、白银、美股,全... 北京时间1月31日凌晨,恐慌性抛售席卷全球贵金属市场。 现货白银日内跌幅一度扩大至34.67%,从1...
OpenAI详解AI代理如何应... AIPress.com.cn报道 1月31日消息,OpenAI 在一篇官方博客中介绍了其 AI 代理...
21亿减值离场,分众掀开了网贷... 作为广告行业巨头的分众传媒,近期的几则公告却意外挑开了网贷行业正面临的艰难现状。 分众传媒近日发布的...
披露换手率、新增中长期业绩!公... 1月30日,中国证监会就《公开募集证券投资基金信息披露内容与格式准则第2号——定期报告的内容与格式》...
40年最大单日跌幅!现货黄金价... 美国总统特朗普提名凯文·沃什(Kevin Warsh)出任美联储主席,引爆市场鹰派预期,贵金属遭恐慌...
一纸提名引爆史诗级抛售:现货白... 1月31日,周五(1月30日)纽约时段,国际贵金属价格大幅跳水,其中现货白银一度跌超36%,黄金最高...
股票行情快报:工商银行(601... 证券之星消息,截至2026年1月28日收盘,工商银行(601398)报收于7.2元,下跌0.41%,...
002514、300087,被... 两家公司被证监会立案调查。 1月30日,宝馨科技(002514.SZ)公告称,公司及公司实际控制人马...
中山东方医院标准化就诊流程:从... 在医疗服务质量不断提升的今天,标准化就诊流程建设已成为医院提升服务效率、改善患者体验的重要抓手。医院...
彩票卖不动了?去年全国彩票收入... 中国彩票收入增速持续放缓。 1月30日,财政部公布2025年12月份全国彩票销售情况。2025年全年...
原创 超... 当消费者为家中购置新物品时,功能之外,产品在“家”中的融入感、协调性如何,正成为越来越重要的考量——...
寒武纪预计2025年至高盈利2... 《科创板日报》1月30日讯(记者 郭辉)寒武纪发布2025年年度业绩预告。 公告显示,寒武纪预计20...
2025年我国基本医保统筹基金... 2025年我国基本医保统筹基金收入约2.95万亿元 新华社北京1月30日电(记者彭韵佳)记者1月3...