SpringBoot 配置文件使用@ @取值

目录

一、背景

二、遇到的问题

三、解决办法


一、背景

        (1)我在项目中引入了如下依赖,目的是开启SpringBoot为我们提供的监控(Actuator)功能。


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

        (2)引入了上述依赖后,在项目的application.yml文件里面进行如下配置,开启监控功能

说明:至于下面这些配置项该如何配置,以及这些配置项的含义是什么,需要自己去学习下SpringBoot的监控功能模块,相关网址如下(以下网址供参考,网上还有很多其他学习资源可以自行搜索):

  • Spring Boot Actuator: Production-ready Features
  • 或者参考如下两篇博客
    • SpringBoot的监控(Actuator) 功能
    • 监控之Spring Boot Admin
management:
  endpoints:
    enabled-by-default: true
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always
    info:
      enabled: true
    metrics:
      enabled: true

(3)启动项目,访问SpringBoot为我们提供的监控端点信息,如下:

SpringBoot 配置文件使用@ @取值_第1张图片 

二、遇到的问题

(1)当访问 http://localhost:9051/actuator/info时,发现并没有任何输出,如下图:

SpringBoot 配置文件使用@ @取值_第2张图片

(2)此时我们需要自己在 application.yml文件中配置 info监控端点的信息,配置如下:

SpringBoot 配置文件使用@ @取值_第3张图片

(3)此时发现项目启动失败,报错信息如下:

SpringBoot 配置文件使用@ @取值_第4张图片 

三、解决办法

(1)解决方案之一

        在项目的pom.xml文件里面添加如下配置项:

SpringBoot 配置文件使用@ @取值_第5张图片 

        然后 Reload project,如下图:

SpringBoot 配置文件使用@ @取值_第6张图片 

(2)再次启动项目,发现可以正常启动 

访问 http://localhost:9051/actuator/info,结果如下图:

SpringBoot 配置文件使用@ @取值_第7张图片 

你可能感兴趣的:(SpringBoot,spring,boot,java,spring,安全)