question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getURI() in EurekaServiceInstance misses custom contextPath.

See original GitHub issue

I have several Spring Boot Apps with REST endpoints with custom server.contextPath’s which use @EnableDiscoveryClient to register themselves in the eureka service registry.

The applications are registered with eureka at startup and later queried by a management application. I just found out that the URIs returned by

org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance.getUri()

only contain scheme,hostname and port but no custom context-path.

The URIs were returned by discoveryClient.getInstances(serviceId) where discoveryClient is an EurekaDiscoveryClient.

The URI one gets via

public URI getUri() {
  return DefaultServiceInstance.getUri(this);
}

looks like:

http://localhost:8761

The proper URI would be:

http://localhost:8761/mycontextpath/

I fixed tested this by locally shadowing the org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient and replacing the body of the URI getUri() method with:

@Override
public URI getUri() {

  //HACK to get proper URI with context-path back
  //return DefaultServiceInstance.getUri(this);
  return URI.create(this.instance.getHomePageUrl());
}

With that adjustment the org.springframework.cloud.client.ServiceInstance that I got back returned the proper service URIs.

I think the op of the issue #500 has the same problem.

Another Problem was that I needed to explicitly declare a

@Bean
public EurekaInstanceConfig eurekaConfigBean() {
  return new EurekaInstanceConfigBean();
}

in order to get custom eureka instance settings in an applications.yml file taken into account at all but I guess that’s for another issue 😉

server:
  port: 9999
  context-path: /admin
...
eureka:
  instance:
    statusPageUrlPath: /admin/manage/info
    homePageUrlPath: /admin/
    healthCheckUrlPath: /admin/manage/health
    non-secure-port: ${server.port:9999}
    ...

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:13
  • Comments:56 (15 by maintainers)

github_iconTop GitHub Comments

7reactions
spencergibbcommented, Dec 11, 2019

We’ve decided as a team not to support this.

4reactions
spencergibbcommented, Jul 19, 2017

It’s all or nothing and doing “all” is a big effort.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Eureka server does not find context-path in client url
When a client application is registered into Spring Eureka server the client id appears at dashboard, but the link url only contains the...
Read more >
Spring Boot Change Context Path - Baeldung
Learn various ways of changing the context path in your Spring Boot application. ... there are cases when we do want to have...
Read more >
Blog - Configuring a Dynamic Context Path in Spring Boot
Weighing the options. To understand the need for a custom solution it's worth noting the alternatives. In order to have multiple context paths, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found