Skip to content

Commit 9f0d63b

Browse files
committed
Add documentation for FeignClientBuilder
1 parent 4a773bd commit 9f0d63b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/modules/ROOT/pages/spring-cloud-openfeign.adoc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,46 @@ protected interface DemoFeignClient {
879879
}
880880
----
881881

882+
883+
=== FeignClientBuilder
884+
885+
`FeignClientBuilder` allows programmatic creation of Feign clients without using the `@FeignClient` annotation.
886+
887+
It builds clients in the same way as `@FeignClient`, but provides flexibility for dynamic use cases.
888+
889+
Unlike `@FeignClient`, which defines clients statically, `FeignClientBuilder` allows creating clients dynamically at runtime.
890+
891+
==== Basic Usage
892+
893+
[source,java,indent=0]
894+
----
895+
@Autowired
896+
private ApplicationContext applicationContext;
897+
898+
FeignClientBuilder builder = new FeignClientBuilder(applicationContext);
899+
900+
MyClient client = builder
901+
.forType(MyClient.class, "myClient")
902+
.url("http://localhost:8080")
903+
.build();
904+
----
905+
906+
==== Configuration Options
907+
908+
* `url(String url)` - Sets the target URL
909+
* `path(String path)` - Adds a base path
910+
* `contextId(String contextId)` - Unique identifier
911+
* `dismiss404(boolean)` - Ignore 404 errors
912+
* `inheritParentContext(boolean)` - Inherit parent config
913+
* `fallback(Class<? extends T>)` - Fallback class
914+
* `customize(FeignBuilderCustomizer)` - Customize Feign builder
915+
916+
==== When to Use
917+
918+
* Dynamic client creation
919+
* Runtime configuration
920+
* When `@FeignClient` is not sufficient
921+
882922
[[reactive-support]]
883923
=== Reactive Support
884924
As at the time of active development of Spring Cloud OpenFeign, the https://github.com/OpenFeign/feign[OpenFeign project] did not support reactive clients, such as https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/reactive/function/client/WebClient.html[Spring WebClient], such support could not be added to Spring Cloud OpenFeign either.
@@ -893,6 +933,7 @@ We discourage using Feign clients in the early stages of application lifecycle,
893933
Similarly, depending on how you are using your Feign clients, you may see initialization errors when starting your application. To work around this problem you can use an `ObjectProvider` when autowiring your client.
894934

895935
[source,java,indent=0]
936+
896937
----
897938
@Autowired
898939
ObjectProvider<TestFeignClient> testFeignClient;

0 commit comments

Comments
 (0)