Feign 配置式 设置 每个接口里面每个类的 超时时间
时间: 2024-03-06 08:48:19 浏览: 70
你可以通过在Feign接口的方法上使用`@FeignClient`注解来配置超时时间。具体步骤如下:
1. 在Feign接口上使用`@FeignClient`注解,并设置`configuration`属性为自定义的Feign配置类,例如:
```
@FeignClient(name = "example", configuration = FeignConfig.class)
public interface ExampleFeignClient {
// ...
}
```
2. 创建自定义的Feign配置类,并在其中设置超时时间。例如:
```
@Configuration
public class FeignConfig {
@Bean
public Request.Options options() {
return new Request.Options(5000, 5000);
}
}
```
上面的代码表示设置连接超时时间和读取超时时间都为5秒。
3. 在Feign接口的方法上使用`@Override`注解,并调用超时时间配置方法。例如:
```
@FeignClient(name = "example", configuration = FeignConfig.class)
public interface ExampleFeignClient {
@Override
@RequestMapping(method = RequestMethod.GET, value = "/example")
@Headers("Content-Type: application/json")
ExampleResponse getExample(@RequestParam("id") String id);
}
```
上面的代码表示调用`getExample`方法时,会使用配置类`FeignConfig`中设置的超时时间。
阅读全文
相关推荐

















