<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
注册Bean
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
然后使用
@RestController
public class HelloController {
@Autowired
private RestTemplate restTemplate;
@RequestMapping("/hello")
public String hello() {
return "Hello from Spring Boot!";
}
@RequestMapping("/chaining")
public String chaining() {
ResponseEntity<String> response = restTemplate.getForEntity("http://localhost:8080/hello", String.class);
return "Chaining + " + response.getBody();
}
}
ribbon 拦截了resttemplate 进行了负载