You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot Actuator/info接口返回空值,如何排查解决?

Actuator /info接口返回空值的排查与解决方案

以下是针对你遇到的问题的具体排查和解决步骤:

  • 检查配置文件格式正确性
    不同配置文件类型有严格的语法要求:

    • 若使用application.yml,必须保证缩进正确,层级清晰:
      info:
        app:
          name: My App
          description: First trial
          version: 1.0.0
      management:
        endpoints:
          web:
            exposure:
              include: health,info
        info:
          env:
            enable: true
      
    • 若使用application.properties,确保键值对无拼写错误、多余空格或换行:
      info.app.name=My App
      info.app.description=First trial
      info.app.version=1.0.0
      management.endpoints.web.exposure.include=health,info
      management.info.env.enable=true
      
  • 验证依赖版本兼容性
    确保spring-boot-starter-actuator的版本与Spring Boot主版本完全匹配,比如Spring Boot 3.x需对应3.x版本的actuator依赖,版本不兼容会导致配置逻辑失效。

  • 排查自定义InfoContributor的影响
    如果项目中存在自定义的InfoContributor实现类,可能会覆盖默认的信息收集逻辑,导致配置的info.app.*字段无法展示。可暂时注释该类,重启服务后测试接口。

  • 确认配置是否被正确加载
    注入Environment对象打印配置值,验证配置是否被读取:

    @Autowired
    private Environment env;
    
    @PostConstruct
    public void checkInfoConfig() {
        System.out.println("info.app.name: " + env.getProperty("info.app.name"));
    }
    

    若打印结果为空,需检查配置文件位置是否在src/main/resources下,或是否存在多环境配置导致当前环境未加载目标配置。

  • 检查安全框架拦截规则
    若项目使用Spring Security等安全组件,需确保/actuator/info接口允许访问。例如在Spring Security配置中添加:

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers("/actuator/info").permitAll()
            .anyRequest().authenticated();
    }
    

内容的提问来源于stack exchange,提问作者Muhammet Gaffaroğlu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 16:02:03