Let's create the HomeController class and auto-wire com.netflix.discovery.EurekaClient:
package com.dineshonjava.eurekaclient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.Controller; import com.netflix.appinfo.InstanceInfo; import com.netflix.discovery.EurekaClient; import com.netflix.discovery.shared.Application; @Controller public class HomeController { @Autowired private EurekaClient eurekaClient; public String serviceUrl() { Application application = eurekaClient.getApplication("spring-cloud-eureka-client"); InstanceInfo instanceInfo = application.getInstances().get(0); String hostname = instanceInfo.getHostName(); ...