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

相关内容

热门资讯

在大吉订购APP订购交易亏损被...   近期,不少投资者反映在“大吉订购App”上投资白银、铂金等商品遭遇严重亏损。该平台宣称提供现货订...
铂银壹号APP商品订购交易亏损...   许多中小投资者误以为网上的“商品现货订购”是合规合法的理财渠道,殊不知这背后隐藏着巨大的合规风险...
兴鑫淘金APP贵金属订购交易亏...   白银、贵金属或其他商品类投资,除国家批准的正规期货交易场所及持牌期货公司外,市面上大量第三方交易...
铂银掘金APP无资质的违规平台...   铂银掘金等平台的投资者,往往是被“注册送现金”“充值返现券”“首单免亏”等广告话术吸引,进而下载...
八方淘金APP订购交易不合规,...   “八方淘金APP”“铂银掘金APP”“铂银壹号APP”等软件被指以“现货订购”为名,实际采用高杠...
在指尖订购APP订购商品亏损被...   指尖订购APP这类平台,表面是“订购交易”,实则是披着电商外衣的非法期货陷阱。绝大多数投资者被蒙...
在犀贝易购APP做商品订购交易...   市面上打着“现货投资”“贵金属交易”旗号的APP并不少,但真正合规、受监管的平台并不多。犀贝易购...
易达淘金APP虚假商品订购交易...   易达淘金APP存在严重的虚假宣传与违规交易行为。该平台打着“商品订购”的旗号,实则通过不合规的交...
大浪淘金APP白银订购亏损被骗...   大浪淘金APP最隐蔽的套路,在于其完全封闭的内盘交易系统。表面上,它宣称与国际贵金属市场接轨;实...
一品好购APP上订购白银出现亏...   一品好购APP原名“一品订购”,运营方为上海宝智未来信息技术有限公司。近期不少投资者反映在该平台...
九州订购APP贵金属订购投资骗...   九州订购APP正通过抖.音、快手、今日头条等平台大量投放投资广告,用“5元起投”“充值返现”“0...
坚锅淘金APP交易软件并不正规...   当前,市面上大量所谓的“现货商城订购”交易软件,早已偏离了正常的实物商品买卖,演变为高杠杆、高手...
斗金订购APP贵金属期货交易骗...   斗金订购APP的投资者往往被铺天盖地的广告宣传所诱导——注册即送现金、充值返现券等看似诱人的福利...
警惕!云启购APP违规经营,披...   "5元起投、充值返现、稳赚不赔"——这些诱人的广告语背后,可能是一个精心设计的金融陷阱。  近期...
量子淘金APP贵金属投资不合规...   "4元起投""充值返券""月入过万"——这些极具诱惑力的广告语在短视频平台、社交软件上铺天盖地。...
鑫汇智投APP贵金属商品订购骗...   鑫汇智投APP非法期货投资骗局,受害者在投资过程中根本不懂交易,也不去研究和验证这个平台是否正规...
矅光智策APP平台违规经营非法...   矅光智策APP对外宣称是“商城订购”“现货交易”,但查询其经营范围,并未显示具备开展现货期货交易...
黄金珠宝怎么选?内侧刻字都代表... 潮新闻客户端 记者 马焱 通讯员 任倩影 9月8日下午,“云游杭州 乐购金秋”——“浙城·浙放心”活...
原创 冰... 最近全球国债市场正在上演魔幻一幕: 美债、日债、欧债遭遇猛烈抛售,收益率冲到几十年新高,美国财政部都...
日韩股市开盘表现分化 上证报中国证券网讯 9月9日,日韩股市开盘表现分化,韩国综合指数开盘上涨0.26%,报6972.87...