目录

一 简单的info

 二 复杂点的info


info端点:书写应用相关的内容

一 简单的info

要在下图的蓝框处设置自定义的info信息

修改client的配置文件如下:

#设置端口,client的端口不要和server的端口冲突
server:
  port: 81
spring:
  boot:
    admin:
      client:
        # 此url指向server端
        url: http://localhost:8080

management:
#  开启了health 信息
  endpoint:
    health:
      show-details: always
    #设置单个info端点开放
    info:
      enabled: true

  #  设置web端开启了全部信息
  endpoints:
    web:
      exposure:
#        *别忘加引号
        include: "*"
#      开放全部端点
    enabled-by-default: true

#书写应用相关的内容
info:
#  在info中设置了一个author,它的值是 qing
  author: qing
  company: 晴
  appName: @project.artifactId@
  version: @project.version@

关于@@的使用,相关文档

如果info未显示,请修改client程序的 springboot的版本为2.6以下,以及保持client坐标版本与springboot 同步

我之前是2.7.1的版本就不显示info

修改成2.5.4 就显示了

 二 复杂点的info

在client程序里自定义一个config类

package com.qing;

import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class InfoConfig implements InfoContributor {
    @Override
    public void contribute(Info.Builder builder) {
        //设置单条信息
        builder.withDetail("runtime:",System.currentTimeMillis());
        //设置多条信息
        Map map =  new HashMap();
        map.put("水果:","apple");
        Map map2 =  new HashMap();
        map.put("家具:","桌子");
        //支持链式编程
        builder.withDetails(map).withDetails(map2);

    }
}

总结

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐