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

相关内容

热门资讯

A股“苹果产业链”巨头冲刺港交... 来源:大河财立方 【大河财立方消息】A股市值近3000亿元的“苹果产业链”巨头——立讯精密拟登陆港交...
为正生物IPO辅导:80后女总... 瑞财经 刘治颖 近日,厦门为正生物科技股份有限公司(以下简称:为正生物)披露关于向不特定合格投资者公...
沪深300ETF指数基金:7月... 证券之星消息,7月24日,沪深300ETF指数基金(515390)融资买入224.73万元,融资偿还...
泰鹏智能:7月24日融资买入9... 证券之星消息,7月24日,泰鹏智能(873132)融资买入94.8万元,融资偿还71.38万元,融资...
宁波银行业绩快报:上半年净利润... 7月24日晚间,宁波银行对外披露2025年半年度业绩快报,公司上半年营业收入371.60亿元,同比增...
我省油气田企业增值税管理办法出... 为加强石油天然气企业增值税征收管理,根据《财政部 税务总局关于印发〈油气田企业增值税管理办法〉的通知...
深圳能源2025年度科技创新大... 7月24日,深圳能源召开2025年度科技创新大会。受访单位供图 深圳能源成立科技创新咨询委员会。受...
期货市场沉淀资金创7783亿历... 近期期货市场资金流入呈现加速态势,沉淀资金总量达到近7783亿元的历史新高。这一数据自6月25日以来...
经学与中国古典学的关系 □景海峰 “以小学为经学”和“即经学史以为经学”的现状 经学曾经是儒学的主干形式,自晚清瓦解以来,已...
价格法修正草案公布,强调“反内... 政策面再出“反内卷”利好,7月24日,《中华人民共和国价格法修正草案》公开征求意见:明确不正当价格行...
原创 特... 关税风暴:特朗普贸易战的全球冲击波 8月1日,一场由美国总统特朗普发起的全球贸易战即将进入高潮。看似...
2024消费品上市公司研究报告... 《2024消费品上市公司研究报告》 (内容出品方:和君咨询x新华网) 报告共计:40页 本研报通过对...
特斯拉Q2营收下滑12%,马斯... 特斯拉于7月24日公布了2025年第二季度财报,数据显示总营收降至225.0亿美元,同比下滑12%;...
衣食住行跟我逛|“今年更甜!”... 盛夏时节,誉称为“紫水晶”的黑葡萄迎来最佳赏味期。近日,扬子晚报/紫牛新闻记者走访苏州市场发现,多数...
棕榈油与油菜籽:印尼库存降,马... 【印尼5月末棕榈油库存下滑,马棕7月上旬增产,加菜籽预估调整】印尼棕榈油协会数据显示,因出口激增,印...
康佳易主华润 半导体业务整合成... 康佳集团股份有限公司是深圳首家营业收入超百亿元的工业企业。 来源:康佳集团 靴子落地。在长达三个多月...
英特尔营收超预期,宣布裁员,C... 英特尔数据中心+AI收入超预期难掩盈利困境,英特尔CEO未能证明公司将扭亏为盈,股价应声下跌。 周四...
我国新药好药呈现快速增长态势:... 央视网消息:国家药监局最新统计显示,我国上半年批准创新药43个,同比增长59%,接近2024年批准创...
赛峰集团宣布完成对柯林斯宇航飞... 赛峰集团宣布完成对柯林斯宇航(Collins Aerospace)飞行控制与作动业务的收购。该业务为...
中国最大农业互联网公司即将登录... 来源:ACN亚太商讯 近日,中国领先的农产品B2B数字化服务公司一亩田集团向美国证券交易委员会(SE...