当前位置: 首页 > 编程笔记 >

详解配置spring-boot-actuator时候遇到的一些小问题

蒙经纶
2023-03-14
本文向大家介绍详解配置spring-boot-actuator时候遇到的一些小问题,包括了详解配置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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持小牛知识库。

 类似资料:
  • 本文向大家介绍详解spring-boot actuator(监控)配置和使用,包括了详解spring-boot actuator(监控)配置和使用的使用技巧和注意事项,需要的朋友参考一下 在生产环境中,需要实时或定期监控服务的可用性。spring-boot 的actuator(监控)功能提供了很多监控所需的接口。简单的配置和使用如下: 1、引入依赖: 如果使用http调用的方式,还需要这个依赖:

  • 本文向大家介绍Spring Boot的Profile配置详解,包括了Spring Boot的Profile配置详解的使用技巧和注意事项,需要的朋友参考一下 Profile 是Spring Boot用来针对不同的环境对不同的配置提供的支持,全局Profile配置使用application-{profile}.properties,如: application-dev.properties 可以表示为

  • 本文向大家介绍spring boot 日志配置详解,包括了spring boot 日志配置详解的使用技巧和注意事项,需要的朋友参考一下 最近在学习spring boot框架的路上,今日看了一下spring boot日志配置,顺便留个笔记记录一下。 1.新建logback.xml文件   内容如下: 2.然后在application.properties文件中假如如下代码: 3.这时就可以使用log

  • 1. 前言 Spring Boot 可以在零配置的情况下使用,但是不代表 Spring Boot 完全不需要配置文件。 举一个简单的例子, Spring Boot 开发的 Web 项目默认的启动端口是 8080 。如果我们想更换启动端口,通过配置文件去修改是比较好的。如果放到代码中,修改一个端口都要重新编译下程序,岂不烦哉? 配置文件不是必须的,但是如果想实现一些个性化的功能,还是需要用到配置文件

  • 本文向大家介绍Spring Boot Log4j2的配置使用详解,包括了Spring Boot Log4j2的配置使用详解的使用技巧和注意事项,需要的朋友参考一下 后台程序开发及上线时,一般都会用到Log信息打印及Log日志记录,开发时通过Log信息打印可以快速的定位问题所在,帮助我们快捷开发。程序上线后如遇到Bug或错误,此时则需要日志记录来查找发现问题所在。 Spring Boot 可以集成很

  • 我创建并尝试使用构建项目,但它不工作。不是这个项目,我试着构建我的所有项目,但在我的ubuntu笔记本电脑上不工作 [信息]扫描项目...从中心下载:https://repo . maven . Apache . org/maven 2/org/spring framework/boot/spring-boot-starter-parent/2 . 6 . 11/spring-boot-start