当前位置: 首页 > 知识库问答 >
问题:

Spring Boot/Cloud Eureka DiscoveryClient--目前还不知道这样的主机

何雅惠
2023-03-14

错误:不知道这样的主机

我在努力

@Autowired
private DiscoveryClient discoveryClient;

并且做

 discoveryClient.getInstances("myappservice-name").forEach((ServiceInstance s) -> {
            System.out.println(ToStringBuilder.reflectionToString(s));
        });
@RequestMapping("/service-instances/{applicationName}")     public
 List<ServiceInstance> serviceInstancesByApplicationName(

bootstrap-spring.application.name=pluralsight-toll-service

应用道具

server.port=0
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true

eureka.instance.instance-id=${spring.application.name}:${random.int}
eureka.instance.hostname=localhost
management.endpoints.web.exposure.include=*

应用程序

@SpringBootApplication
@EnableEurekaClient
public class PluralsightEurekaTollrateServiceApplication {
spring.application.name=pluralsight-tollrate-billboard
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
server.port=8081
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
management.endpoints.web.exposure.include=*
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
public class PluralsightEurekaTollrateBillboardApplication {
   @LoadBalanced
    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }
    
    @Autowired
    RestTemplate restTemplate;
    
    @RequestMapping("/dashboard")
    public String GetTollRate(@RequestParam int stationId, Model m) {
        
        TollRate tr = restTemplate.getForObject("http://pluralsight-toll-service/tollrate/" + stationId, TollRate.class);
    

如何使用名称从客户端调用服务

共有1个答案

澹台浩广
2023-03-14

修正了问题

这完全取决于客户机项目依赖关系

    <!-- <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-netflix-eureka-client</artifactId>
        <version>3.0.3</version>
    </dependency> -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>

名字太接近了spring-cloud-netflix-eureka-client是错误的spring-cloud-starter-netflix-eureka-client是正确的

 类似资料: