覆盖Spring Cloud中的InfoEndpoint

时间:2015-04-20 17:21:52

标签: spring-boot spring-cloud

最初在GitHub上发布此问题,但可能更适合此论坛......

我们正在为在Eureka中注册的Spring Cloud服务分配一些自定义元数据值,现在我们需要在Eureka仪表板中查看这些值。我正在尝试扩展/覆盖/ info端点,以便从Eureka Dashboard可以看到我们的元数据,Eureka Dashboard已经提供了到每个注册服务的/ info端点的超链接。我曾经读过,我可以通过将我自己的bean版本添加到上下文来覆盖Boot自动配置的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   bean:class [null];范围=;抽象= FALSE; lazyInit = FALSE;   autowireMode = 3; dependencyCheck = 0; autowireCandidate = TRUE;   初级= FALSE; factoryBeanName = endpointConfig;   factoryMethodName = infoEndpoint; initMethodName = NULL;   destroyMethodName =(推断);在类路径资源中定义   [com / acme / ecom / items / config / EndpointConfig.class]] [root bean:   class [null];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 3;   dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE;   factoryBeanName = org.springframework.cloud.autoconfigure.RefreshAutoConfiguration $ InfoEndpointRebinderConfiguration;   factoryMethodName = infoEndpoint; initMethodName = NULL;   destroyMethodName =(推断);在类路径资源中定义   [组织/ springframework的/云/自动配置/ RefreshAutoConfiguration $ InfoEndpointRebinderConfiguration.class]]

似乎我的InfoEndpoint bean版本正在被来自Spring云的另一个bean所取代(org/springframework/cloud/autoconfigure/RefreshAutoConfiguration$InfoEndpointRebinderConfiguration.class)

我是否正确阅读?如果是这样,我该如何预防?

谢谢, 比尔

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

不知道这是否真的有帮助,但我在我的application.yml中有这个,我可以在服务上看到这些信息。

{
"component": "Service Name"
}

所以当我用/ info命中服务时,这就是我所看到的: -

API.Commit()

希望这有帮助。