springcloud-基于OpenFeign的服务调用

1.依赖

        <!--引入open feign依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
    </dependencies>

 2.启动注解

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class UserservicesApplication {

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

}

 3.接口

@FeignClient("productservices")
public interface ProductClient {
    @RequestMapping("/product/findAll")
    public Map findAll();
}

 4.服务调用

    @Autowired
    private ProductClient productClient;

    @RequestMapping("/user/showProductMsg")
    public Map showProductMsg() {
        Map msg = productClient.findAll();
        return msg;
    }

 5.超时设置

feign.client.config.default.connectTimeout=5000 #配置所有服务连接超时
feign.client.config.default.readTimeout=5000	#配置所有服务等待超时

 

posted @ 2020-08-09 12:55  陶海军  阅读(213)  评论(0编辑  收藏  举报