SpringCloud-Ribbon使用学习笔记

1.服务消费者pom.xml引入Eureka依赖

 
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        

2.加上@LoadBalanced注解


@SpringBootApplication
@EnableDiscoveryClient
public class AutoApplication {

    public static void main(String[] args) {
        SpringApplication.run(AutoApplication.class,args);
    }

    @LoadBalanced
    @Bean
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }
}

3.调用时url改造

@GetMapping("checkState/{userId}")
    public Integer findByResume(@PathVariable Long userId){
        String url = "http://find/resume/openstate/"+userId;
        System.out.println(url);
        return restTemplate.getForObject(url,Integer.class);
    }

你可能感兴趣的:(spring,cloud,ribbon,spring)