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博客

相关内容

热门资讯

王凤英入职小鹏3年终获股权,此... 5月7日消息,小鹏汽车披露的监管及年报信息显示,公司总裁王凤英已正式进入股东名册,入职小鹏3年后股权...
五块钱红酒卖断货,便宜红酒为何... 最近一段时间,中国的酒类消费市场可以说是显得格外奇怪,一方面,各种高端酒特别是白酒的消费量出现了明显...
财联社C50风向指数调查:4月... 财联社5月8日讯(记者 夏淑媛)新一期财联社“C50风向指数”结果显示,市场机构对4月新增人民币贷款...
央视硬刚国际足联拒掏20亿,背... 作者| 史大郎&猫哥 来源| 是史大郎&大猫财经Pro 央视这次太刚了,离世界杯开幕还有1个月,死活...
新CEO上任直接放大招!Air... 快科技5月8日消息,苹果即将上任的CEO John Ternus对未来一系列新产品充满信心,称这些设...
“特朗普拟邀英伟达、波音等CE... 据路透社当地时间5月7日报道,特朗普政府正邀请英伟达、苹果、埃克森美孚、波音等大公司首席执行官,于下...
世界杯,还能看到直播吗? 2026年美加墨世界杯距离开幕,仅剩一个多月时间。多方信息显示,中央广播电视总台(以下简称“央视”)...
机构警告AI芯片热潮风险,超威... 5月7日,据央视财经,隔夜超威半导体公司(AMD)股价飙升近19%,带动AI芯片热潮持续升温。AMD...
银行员工转走储户1800万最新... 银行员工转走储户1800万最新进展:2名储户已收到银行全部款项
原创 中... 1994年,安徽省的经济格局曾发生过一次戏剧性的转折。在那一年,一座名为安庆的城市,其国内生产总值(...
昆都仑区:政策“蓄力”消费焕新 “一台5000多元的空调,叠加‘国补’和商场的以旧换新活动,能优惠1000元左右,旧机还能免费上门拆...
乐悦置业竞得佛山顺德乐从镇一商... 观点网讯:5月6日,佛山市顺德区乐从镇一商业地块成功出让,由广东省乐悦置业有限公司竞得,乐从南区·邻...
原创 亦... 《爱情没有神话》这部剧,一开始的命运颇为多舛,经历了几次撤档的波折后,终于在观众面前亮相,但其首播的...
美联储34年最大分歧叠加油价飙... 美联储按预期维持利率不变,但内部出现34年来最严重分歧,叠加布油创2022年6月以来新高,美债遭抛售...
支付宝消费券回收后,资金是否支... 摘要: 支付宝消费券回收变现后,资金能否直接转入信用卡?本文解答到账方式的相关规则,帮助用户了解资金...
中医介绍5个化痰穴位!收藏这篇... 很多人忽略了“痰”的危害,觉得咳几下就没事,殊不知,肺里的痰长期堆积,只会一步步加重身体负担。 中医...
黄金平台“杰我睿”涉嫌经济犯罪... 红星资本局5月7日消息,深圳水贝知名金店“杰我睿”兑付困难事件有了新进展。日前,深圳市公安局罗湖分局...
多地出台购房新政促楼市升温 记... 今年的“五一”假期,伴随着多个城市楼市新政密集落地,在叠加市场信心持续修复的作用下,房地产市场热度持...
谁是五一“吸金王”?这5座城市... 来源:市场资讯 (来源:21城市观) 哪座城市成为“五一”假期的大赢家? 图源:摄图网 作者|赵晓...
“低招低裁”格局稳固劳动力市场... 智通财经APP获悉,美国上周初请失业金人数在经历前一周回落至近几十年来最低水平后出现小幅反弹,表明尽...