Bill Bauernschmidt
Bill Bauernschmidt

Reputation: 11

Overriding the InfoEndpoint in Spring Cloud

Originally posted this as an issue in GitHub but might be better suited for this forum...

We are assigning some custom metadata values to our Spring Cloud services that are being registered in Eureka and we now need to have visibility to those values in the Eureka dashboard. I am trying to extend/override the /info endpoint so that our metadata is visible from the Eureka Dashboard which already provides hyperlinks to each registered service's /info endpoint. I had read that I could override the Boot autoconfigured InfoEndpoint by just adding my own version of that bean to the context. I am trying to test with the following configuration 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);
  }
}

When I run my service though and hit its /info endpoint I do not see this test value. I also see this in the log:

2015-04-17 14:54:23,910 main INFO DefaultListableBeanFactory - - - - Overriding bean definition for bean 'infoEndpoint': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=endpointConfig; factoryMethodName=infoEndpoint; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/acme/ecom/items/config/EndpointConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.cloud.autoconfigure.RefreshAutoConfiguration$InfoEndpointRebinderConfiguration; factoryMethodName=infoEndpoint; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/cloud/autoconfigure/RefreshAutoConfiguration$InfoEndpointRebinderConfiguration.class]]

It appears that my version of the infoEndpoint bean is being replaced with another bean coming from Spring cloud (in org/springframework/cloud/autoconfigure/RefreshAutoConfiguration$InfoEndpointRebinderConfiguration.class).

Am I reading this correctly? And if so how do I prevent it?

Thanks, Bill

Upvotes: 0

Views: 369

Answers (2)

Grinish Nepal
Grinish Nepal

Reputation: 3063

Don't know if this will actually help but I have this in my application.yml which I can see when I do /info on the service.

info:
  component: Service Name

so when i hit the service with /info this is what i see:-

{
"component": "Service Name"
}

Hope this helps.

Upvotes: 0

Dave Syer
Dave Syer

Reputation: 58124

If you put your metadata in info.* e.g. info.myfoo=${eureka.instance.metadataMap.myfoo:none} it will show up in the default /info endpoint.

Upvotes: 0

Related Questions