详解配置spring-boot-actuator时候遇到的一些小问题
作者:LOC_Thomas 时间:2022-03-17 17:04:08
前言
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
标签:spring,boot,actuator
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java之常用类小结案例讲解
2022-10-08 07:34:24
![](https://img.aspxhome.com/file/2023/5/67995_0s.png)
C#多线程之任务的用法详解
2023-08-27 10:51:18
![](https://img.aspxhome.com/file/2023/9/69209_0s.png)
java之static关键字用法实例解析
2023-11-21 14:42:49
![](https://img.aspxhome.com/file/2023/8/78388_0s.png)
Visual Studio 2022 安装低版本 .Net Framework的图文教程
2023-06-22 19:18:44
![](https://img.aspxhome.com/file/2023/0/78990_0s.png)
java poi设置生成的word的图片为上下型环绕以及其位置的实现
2023-05-23 03:12:08
![](https://img.aspxhome.com/file/2023/5/76285_0s.png)
Spring Boot之AOP配自定义注解的最佳实践过程
2023-01-27 17:41:02
![](https://img.aspxhome.com/file/2023/4/77334_0s.gif)
Java中的 stop the world是什么呢
2022-09-11 21:32:42
![](https://img.aspxhome.com/file/2023/5/78925_0s.png)
Java性能优化之数据结构实例代码
2022-01-21 14:46:02
![](https://img.aspxhome.com/file/2023/5/80305_0s.png)
java 请求跨域问题解决方法实例详解
2023-08-24 02:55:11
Java Condition条件变量提高线程通信效率
2022-11-26 13:32:46
Spring注解之@Lazy注解使用解析
2023-08-28 23:12:23
IDEA 2019.1.3 激活码大全
2023-05-09 05:20:37
浅谈Java中复制数组的方式
2022-04-14 23:30:27
详解Java编程中向量(Vector)的应用
2021-05-31 18:14:27
![](https://img.aspxhome.com/file/2023/5/77165_0s.jpg)
Java提示缺少返回语句的解决办法
2021-08-04 19:42:03
![](https://img.aspxhome.com/file/2023/3/66023_0s.png)
Java 实战练手项目之酒店管理系统的实现流程
2022-07-30 09:05:10
![](https://img.aspxhome.com/file/2023/1/71201_0s.png)
Spring多个数据源配置详解
2023-09-20 18:22:18
![](https://img.aspxhome.com/file/2023/6/79936_0s.png)
spring boot 打包jar jar没有主目录清单问题的完美解决方法
2021-08-28 16:07:39
![](https://img.aspxhome.com/file/2023/9/65149_0s.png)
Maven生命周期和及插件原理用法详解
2021-09-17 09:47:19
![](https://img.aspxhome.com/file/2023/2/75442_0s.png)
java模拟实现双向链表
2022-06-05 09:16:16
![](https://img.aspxhome.com/file/2023/2/62072_0s.jpg)