Python知识分享网 - 专业的Python学习网站 学Python,上Python222
深入探索Zookeeper:实战应用与高效策略 PDF 下载
发布于:2023-12-26 11:49:23
(假如点击没反应,多刷新两次就OK!)

深入探索Zookeeper:实战应用与高效策略 PDF 下载  图1

 

 

资料内容:

 

 

代码编写:
配置 Resttemplate 支持负载均衡方式
1 @SpringBootApplication
2 public class UserCenterApplication {
3
4 public static void main(String[] args) {
5 SpringApplication.run(UserCenterApplication.class, args);
6 }
7
8
9 @Bean
10 @LoadBalanced
11 public RestTemplate restTemplate(){
12 return new RestTemplate();
13 }
14 }
编写测试类:
TestController, Spring Cloud 支持 Feign, Spring RestTemplate,WebClient 以 逻辑名称,
替代具体url的形式访问。
1 import org.springframework.beans.factory.annotation.Autowired;
2 import org.springframework.web.bind.annotation.GetMapping;
3 import org.springframework.web.bind.annotation.RestController;
4 import org.springframework.web.client.RestTemplate;
5
6 @RestController
7 public class TestController {
8
9 @Autowired
10 private RestTemplate restTemplate;
11
12 @GetMapping("/test")
13 public String test(){
14 return this.restTemplate.getForObject( "http://product‐center/getInfo" ,Stri
ng.class);
15 }
16 }