详解配置spring-boot-actuator时候遇到的一些小问题
作者:LOC_Thomas 发布时间:2022-03-17 17:04:08
标签:spring,boot,actuator
前言
spring-boot-actuator是一个spring-boot提供的用于监控组件,只需要在代码中加入依赖就可以了
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
遇到的一些小问题
1.可以加入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
来保证actuator暴露接口的安全性,可以通过 -u 'user:password' 方式来访问basic auth
2.如果项目依赖的是springmvc框架,并且基础的配置文件是 application.yaml的话,可以增加 application.properties 文件来配置安全性的配置.
3.如果加入了security依赖,则所有的接口默认都需要被验证,如果只想 /admin路径下的请求进行验证,则需要加入配置
security.basic.enabled=true
security.basic.path=/admin
security.user.name=admin
security.user.password=password
4.如果项目依赖的是非springmvc框架的话, 需要在依赖中加入mvc的依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
5.如果management.security.enabled的值是false的话,除开health接口还依赖endpoints.health.sensitive的配置外,其他接口都不需要输入用户名和密码了。
6.actuator暴露的health接口权限是由两个配置: management.security.enabled 和 endpoints.health.sensitive组合的结果进行返回的。
management.security.enabled | endpoints.health.sensitive | Unauthenticated | Authenticated |
false | false | Full content | Full content |
false | true | Status only | Full content |
true | false | Status only | Full content |
true | true | No content | Full content |
7.actuator组件里面除开上面提到的metrics和health接口以外,还有很多默认的其他接口,如果它默认的接口不能满足你的需求的话,还可以通过继承它的 AbstractEndpoint 类来实现自己的Endpoint
最后附加一个配置文件例子:
security.basic.enabled=true
security.basic.path=/admin #针对/admin路径进行认证
security.user.name=admin #认证使用的用户名
security.user.password=password #认证使用的密码
management.security.roles=SUPERUSER
management.port=11111 #actuator暴露接口使用的端口,为了和api接口使用的端口进行分离
management.context-path=/admin #actuator暴露接口的前缀
management.security.enabled=true #actuator是否需要安全保证
endpoints.metrics.sensitive=false #actuator的metrics接口是否需要安全保证
endpoints.metrics.enabled=true
endpoints.health.sensitive=false #actuator的health接口是否需要安全保证
endpoints.health.enabled=true
来源:http://www.jianshu.com/p/b0b40038bb93
0
投稿
猜你喜欢
- 本文实例为大家分享了Android实现拼图游戏的具体代码,供大家参考,具体内容如下本人是用 android studio 完成的源码pack
- 介绍  日常的业务开发,我们会重复编写一些代码:日期和字符串相互转换、发送Http请求调用接口、拷贝对象
- java代理有jdk * 、cglib代理,这里只说下jdk * ,jdk * 主要使用的是java反射机制(既java.lang.r
- optString方法会在对应的key中的值不存在的时候返回一个空字符串,但是getString会抛一个JSONException 。 /*
- 问题描述涛涛最近要负责图书馆的管理工作,需要记录下每天读者的到访情况。每位读者有一个编号,每条记录用读者的编号来表示。给出读者的来访记录,请
- 问题情况:在使用 @TableId(type = IdType.AUTO)之后添加的id数字特别大原因:因为在第一次使用的时候没有加注解 所
- 原因分析@Anysc注解会开启一个新的线程,主线程的Request和子线程是不共享的,所以获取为null在使用springboot的自定带的
- 本文实例讲述了Android中TextView显示插入的图片实现方法。分享给大家供大家参考,具体如下:Android系统默认给TextVie
- 前言:在我们使用C# WinForm中,我们有时候是需要或者自己本机的IP地址进行处理,今天我们学习一下如何使用C# Winform获取主机
- 适配器模式是一种重要的设计模式,在 Android 中得到了广泛的应用。适配器类似于现实世界里面的插头,通过适配器,我们可以将分属于不同类的
- 一、什么是建造者模式建造者模式也称生成器模式 定义:将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示(依赖倒转)产品
- 本文实例为大家分享了C#实现猜数字游戏具体代码,供大家参考,具体内容如下给定一个0-100的随机数字猜其大小题目样式:电脑产生一个0到100
- 一、简介相信大家用eclipse上的模拟器会觉得很慢很卡,这里给大家介绍个好东西安卓模拟器genymotion。了解更多,可到此网站http
- 打开首页,明显看到链接是https打头,https和http的通信协议差别,在于https安全性更高:http和https的差别很明显,二者
- spring-MVC实现简单的登录功能,供大家参考,具体内容如下今天我学习了spring-MVC实现简单的登录功能,本篇博客就讲解如何使用s
- 首先说的是LinearLayout布局下的居中一般是这样的:(注意:android:layout_width="fill_pare
- 前言今天在做新需求的时候,活动有多个类型可以选择,UI给的设计图为多行多列排版,且单项选择,细细想来,谷歌并没有为我们提供类似的控件,初步设
- RestTemplate反序列化嵌套对象假设某个接口返回的数据如下格式{ "msg" : "ok&
- 今天在于硬件进行交互的过程中,要到了了需要两个数组进行合并,然后对数组进行反转和加密操作,以下是两个byte数组合并的方法。/** *
- 前言:各位小伙伴们,大家好,一日不见,如隔一日,今天我给大家分享一下大家在学习java过程当中遇到的一个问题,也是一道面试题,java中,O