当前位置: 首页 > 工具软件 > RibbonMenu > 使用案例 >

ribbon使用

双子民
2023-12-01
@SpringBootApplication
@EnableDiscoveryClient
public class eurekaClient1 {
    public static void main(String[] args) {
        SpringApplication.run(eurekaClient1.class, args);
    }

    @Bean
    @LoadBalanced
    RestTemplate restTemplate(){
        return new RestTemplate();
    }
}

@RestController
public class ServiceInstanceRestController {

    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/service-instances/{applicationName}")
    public List<ServiceInstance> serviceInstances(@PathVariable String applicationName) {
        return this.discoveryClient.getInstances(applicationName);
    }

    @RequestMapping("/")
    public String sayhello() {
        String forObject = restTemplate.getForObject("http://HYSTRIXTEST/", String.class);
        System.out.println(forObject);
        return forObject;
    }

 

 类似资料: