【问题标题】:Overriding the InfoEndpoint in Spring Cloud覆盖 Spring Cloud 中的 InfoEndpoint
【发布时间】:2015-06-27 13:26:23
【问题描述】:

最初将此作为问题发布在 GitHub 中,但可能更适合此论坛...

我们正在为在 Eureka 中注册的 Spring Cloud 服务分配一些自定义元数据值,现在我们需要在 Eureka 仪表板中查看这些值。我正在尝试扩展/覆盖 /info 端点,以便我们的元数据可以从 Eureka 仪表板中看到,该仪表板已经提供了到每个注册服务的 /info 端点的超链接。我读过我可以通过将我自己的 bean 版本添加到上下文中来覆盖引导自动配置的 InfoEndpoint。我正在尝试使用以下配置 bean 进行测试:

@Configuration
public class EndpointConfig {
  @Bean
  public InfoEndpoint infoEndpoint() throws Exception {
    LinkedHashMap<String, Object> info = new LinkedHashMap<String, Object>();
    info.put("name", "value");
    return new InfoEndpoint(info);
  }
}

当我运行我的服务并点击它的 /info 端点时,我看不到这个测试值。我也在日志中看到了这一点:

2015-04-17 14:54:23,910 主要信息 DefaultListableBeanFactory - - - - 覆盖 bean 'infoEndpoint' 的 bean 定义:替换 [Root 豆:类[空];范围=;摘要=假;懒惰初始化=假; 自动线模式=3;依赖检查=0;自动接线候选=真; 主要=假; factoryBeanName=endpointConfig; factoryMethodName=infoEndpoint;初始化方法名=空; destroyMethodName=(推断);在类路径资源中定义 [com/acme/ecom/items/config/EndpointConfig.class]] 与 [Root bean: 类[空];范围=;摘要=假;懒惰初始化=假;自动线模式=3; 依赖检查=0;自动接线候选=真;主要=假; factoryBeanName=org.springframework.cloud.autoconfigure.RefreshAutoConfiguration$InfoEndpointRebinderConfiguration; factoryMethodName=infoEndpoint;初始化方法名=空; destroyMethodName=(推断);在类路径资源中定义 [org/springframework/cloud/autoconfigure/RefreshAutoConfiguration$InfoEndpointRebinderConfiguration.class]]

看来我的 infoEndpoint bean 版本正在被另一个来自 Spring cloud 的 bean 替换(org/springframework/cloud/autoconfigure/RefreshAutoConfiguration$InfoEndpointRebinderConfiguration.class)

我读对了吗?如果是这样,我该如何预防?

谢谢, 比尔

【问题讨论】:

  • 目前没有。我们可以让它可配置。
  • 谢谢!刚刚将其添加到 spring-cloud-commons 存储库中。

标签: spring-boot spring-cloud


【解决方案1】:

如果您将元数据放入info.*,例如info.myfoo=${eureka.instance.metadataMap.myfoo:none} 它将显示在默认的 /info 端点中。

【讨论】:

    【解决方案2】:

    不知道这是否真的有帮助,但我的 application.yml 中有这个,当我在服务上执行 /info 时可以看到。

    info:
      component: Service Name
    

    所以当我使用 /info 访问服务时,这就是我所看到的:-

    {
    "component": "Service Name"
    }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2015-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-11
      • 2017-01-26
      • 2016-05-07
      • 2021-10-24
      • 2015-08-31
      相关资源
      最近更新 更多