博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
配置spring-boot-actuator时候遇到的一些小问题
阅读量:3586 次
发布时间:2019-05-20

本文共 1956 字,大约阅读时间需要 6 分钟。

前言

spring-boot-actuator是一个spring-boot提供的用于监控组件,只需要在代码中加入依赖就可以了

org.springframework.boot
spring-boot-starter-actuator

遇到的一些小问题

1.可以加入依赖

org.springframework.boot
spring-boot-starter-security

来保证actuator暴露接口的安全性,可以通过 -u 'user:password' 方式来访问basic auth

2.如果项目依赖的是springmvc框架,并且基础的配置文件是 application.yaml的话,可以增加 application.properties 文件来配置安全性的配置.

3.如果加入了security依赖,则所有的接口默认都需要被验证,如果只想 /admin路径下的请求进行验证,则需要加入配置

security.basic.enabled=truesecurity.basic.path=/adminsecurity.user.name=adminsecurity.user.password=password

4.如果项目依赖的是非springmvc框架的话, 需要在依赖中加入mvc的依赖

org.springframework
spring-webmvc

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=truesecurity.basic.path=/admin    #针对/admin路径进行认证security.user.name=admin     #认证使用的用户名security.user.password=password   #认证使用的密码management.security.roles=SUPERUSERmanagement.port=11111   #actuator暴露接口使用的端口,为了和api接口使用的端口进行分离management.context-path=/admin   #actuator暴露接口的前缀management.security.enabled=true   #actuator是否需要安全保证endpoints.metrics.sensitive=false   #actuator的metrics接口是否需要安全保证endpoints.metrics.enabled=trueendpoints.health.sensitive=false  #actuator的health接口是否需要安全保证endpoints.health.enabled=true
作者:LOC_Thomas
链接:http://www.jianshu.com/p/b0b40038bb93
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
你可能感兴趣的文章
M1安装环境
查看>>
类加载之双亲委派
查看>>
c++ make_pair&pair
查看>>
C++ mutable
查看>>
剑指offer:面试题18. 删除链表的节点
查看>>
剑指offer:面试题19. 正则表达式匹配
查看>>
剑指offer:面试题24. 反转链表
查看>>
剑指offer:面试题25. 合并两个排序的链表
查看>>
剑指offer:面试题26. 树的子结构
查看>>
剑指offer:面试题27. 二叉树的镜像
查看>>
剑指offer:面试题33. 二叉搜索树的后序遍历序列
查看>>
输出NN乘法表
查看>>
[2005年NOIP普及组] 陶陶摘苹果
查看>>
[2006年NOIP普及组] 数列
查看>>
[2006年NOIP普及组] 数列
查看>>
[2011年NOIP普及组] 数字反转
查看>>
[2008年NOIP普及组] ISBN号码
查看>>
[2010年NOIP普及组] 数字统计
查看>>
计算多项式的值
查看>>
甲流疫情死亡率
查看>>