Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mstykt/31a1eaaf1b12190113a59bcd5a031f00 to your computer and use it in GitHub Desktop.
Save mstykt/31a1eaaf1b12190113a59bcd5a031f00 to your computer and use it in GitHub Desktop.
package com.example.ribbon.client;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class RibbonClientApplication {
public static void main(String[] args) {
SpringApplication.run(RibbonClientApplication.class, args);
}
@LoadBalanced
@Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
}
@RestController
class RibbonController {
private final RestTemplate restTemplate;
RibbonController(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
@GetMapping
public String sayHi() {
return "Answer is: " + restTemplate.getForObject("http://say-hi/", String.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment