Created
May 11, 2020 17:25
-
-
Save mstykt/31a1eaaf1b12190113a59bcd5a031f00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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