我有以下简单设置。
Spring Cloud Eureka Server
-和两个服务PricingService
和DiscountService
。 定价服务呼叫-> DiscountService 。
服务器设置
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
属性
spring.application.name=eureka-server
server.port=8761
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
DiscountService
@SpringBootApplication
@EnableDiscoveryClient
@Slf4j
public class DiscountServiceApplication {
public static void main(String[] args) {
SpringApplication.run(DiscountServiceApplication.class, args);
}
}
@RestController
@RequestMapping("/discount/{product}")
@Slf4j
public class DiscountController{
@GetMapping
public int getDiscountPercentage(@PathVariable("product") String product){
log.info("Getting Discount for Product {}",product);
return 50;
}
}
spring.application.name=discount-service
eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka/
server.port=8081
定价服务
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class PricingServiceApplication {
public static void main(String[] args) {
SpringApplication.run(PricingServiceApplication.class, args);
}
}
@RestController
@Slf4j
class ServiceInstanceRestController {
@Autowired
private DiscountServiceClient discountServiceClient;
@GetMapping("/test/")
public String getPriceForProduct() {
log.info("getPriceForProduct");
int dscount = discountServiceClient.getDiscountPercentage("Test");
log.info("Discount is {}",dscount);
return "Price";
}
}
@FeignClient("discount-service")
interface DiscountServiceClient {
@RequestMapping(method = RequestMethod.GET, value = "/discount/{product}")
int getDiscountPercentage(@PathVariable("product") String product);
}
spring.application.name=pricing-service
eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka/
server.port=8080
eureka.client.fetchRegistry=true
致电折扣服务时,我遇到了异常情况
com.netflix.client.ClientException: Load balancer does not have available server for client: discount-service
at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:483) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
我正在使用 Spring Boot 2.1.4.RELEASE
spring-cloud-starter-netflix-eureka-client
spring-cloud-starter-openfeign
spring-cloud-starter-netflix-eureka-server-server (Fo Server)
我已经检查了Load balancer does not have available server for client的答案 但是对我没用...
我在这里想念什么?
答案 0 :(得分:0)
这还需要依赖执行器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
有关更多详细信息,请参阅以下链接