三、application.yml文件org.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-actuatorotc.orientsec cloud-api-commons1.0-SNAPSHOT org.projectlombok lomboktrue org.springframework.cloud spring-cloud-starter-zookeeper-discovery
server:
port: 80
spring:
application:
name: cloud-order-service
cloud:
zookeeper:
connect-string: 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
四、主启动类
@SpringBootApplication
@EnableDiscoveryClient
public class ZkOrderMain80 {
public static void main(String[] args)
{
SpringApplication.run(ZkOrderMain80.class,args);
}
}
注意一定要加上@EnableDiscoveryClient服务发现的注解
五、controller层controller层依赖RestTemplate负载均衡,如果忘记加@LoadBalanced注解,会报错500
@RestController
@Slf4j
public class ZkOrderController {
private static final String PAYMENT_URL="http://cloud-payment-service";
@Autowired
private RestTemplate restTemplate;
@GetMapping("/consumer/payment/zk")
public String paymentZk()
{
log.info("收到请求");
return restTemplate.getForObject(PAYMENT_URL+"/payment/zk",String.class);
}
}
六、测试
6.1 服务注册
6.2 消费者请求



