FeignClient Configuration Properties (#1942)

* add feign client properties

* configure feign builder from properties if exists

* change string config to class config and add unit test for feign client using configuration properties

* refactoring and add primary flag configuration

* add decode404 in feign client configuration properties

* change unit test properties decode404 to true

* remove lombok from FeignClientProperties and change primary attribute to default-to-properties

fixes gh-1931
This commit is contained in:
Eko Kurniawan Khannedy
2017-07-08 02:31:56 +07:00
committed by Spencer Gibb
parent 0579b326be
commit c2c634707e
6 changed files with 468 additions and 4 deletions

View File

@@ -1042,8 +1042,46 @@ public class FooConfiguration {
This replaces the `SpringMvcContract` with `feign.Contract.Default` and adds a `RequestInterceptor` to the collection of `RequestInterceptor`.
`@FeignClient` also can be configured using configuration properties.
application.yml
[source,yaml]
----
feign:
client:
config:
feignName:
connectTimeout: 5000
readTimeout: 5000
loggerLevel: full
errorDecoder: com.example.SimpleErrorDecoder
retryer: com.example.SimpleRetryer
requestInterceptors:
- com.example.FooRequestInterceptor
- com.example.BarRequestInterceptor
decode404: false
----
Default configurations can be specified in the `@EnableFeignClients` attribute `defaultConfiguration` in a similar manner as described above. The difference is that this configuration will apply to _all_ feign clients.
If you prefer using configuration properties to configured all `@FeignClient`, you can create configuration properties with `default` feign name.
application.yml
[source,yaml]
----
feign:
client:
config:
default:
connectTimeout: 5000
readTimeout: 5000
loggerLevel: basic
----
If we create both `@Configuration` bean and configuration properties, configuration properties will win.
It will override `@Configuration` values. But if you want to change the priority to `@Configuration`,
you can change `feign.client.default-to-properties` to `false`.
NOTE: If you need to use `ThreadLocal` bound variables in your `RequestInterceptor`s you will need to either set the
thread isolation strategy for Hystrix to `SEMAPHORE` or disable Hystrix in Feign.