eureka-consumer-ribbon
系列目录
一、父工程
二、服务注册 eureka
三、服务发现 eureka
四、服务消费 eureka
五、服务消费 ribbon
六、服务消费 openfeign
七、服务降级 hystrix
八、服务监控 hystrix-dashboard
1.建module
2.勾依赖
3.启动类@EnableDiscoveryClient
@SpringBootApplication
@EnableDiscoveryClient
public class EurekaConsumerRibbonApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaConsumerRibbonApplication.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
4.改配置
server.port=9002
spring.application.name=eureka-consumer-ribbon
# 注册到eureka
eureka.client.serviceUrl.defaultZone=http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/
5.Controller
@RestController
public class HelloController {
@Autowired
RestTemplate restTemplate;
@RequestMapping("/hello")
public String hello() {
return restTemplate.getForObject("http://eureka-client/hello", String.class);
}
}
6.启动测试
7.访问http://localhost:9002/hello
8.ribbon完成
下一篇 服务消费 openfeign
工程地址