学无先后,达者为师

网站首页 编程语言 正文

SpringBoot 配置文件使用@ @取值

作者:太自由 更新时间: 2023-12-16 编程语言

目录

一、背景

二、遇到的问题

三、解决办法


一、背景

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

<!-- 引入SpringBoot 监控功能 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

        (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为我们提供的监控端点信息,如下:

 

二、遇到的问题

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

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

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

 

三、解决办法

(1)解决方案之一

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

 

        然后 Reload project,如下图:

 

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

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

 

原文链接:https://blog.csdn.net/qq_23388169/article/details/134806431

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新