详解配置spring

网友投稿 257 2023-03-20


详解配置spring

前言

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

org.springframework.boot

spring-boot-starter-actuatorhttp://

遇到的一些小问题

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=true

security.basic.path=/admin

security.user.name=admin

security.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=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


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:接口管理平台架构设计(接口管理方案)
下一篇:详解Spring Boot配置排序依赖技巧
相关文章

 发表评论

暂时没有评论,来抢沙发吧~