From 8d8f82ad0c07f31c075f95a625db31dc5aa31f72 Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Wed, 30 Nov 2022 22:23:53 +0100 Subject: [PATCH] Add docs and javadocs. --- .../main/asciidoc/spring-cloud-openfeign.adoc | 20 +++++++++++++++++++ .../openfeign/FeignClientSpecification.java | 1 + .../openfeign/FeignClientsRegistrar.java | 1 - ...BeanFactoryInitializationAotProcessor.java | 5 +++++ ...itional-spring-configuration-metadata.json | 6 ++++++ .../cloud/openfeign/aot/FeignAotTests.java | 2 +- 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-openfeign.adoc b/docs/src/main/asciidoc/spring-cloud-openfeign.adoc index a1e7ac4b..e96b3259 100644 --- a/docs/src/main/asciidoc/spring-cloud-openfeign.adoc +++ b/docs/src/main/asciidoc/spring-cloud-openfeign.adoc @@ -78,6 +78,15 @@ TIP: To use `@EnableFeignClients` annotation on `@Configuration`-annotated-class or list them explicitly: `@EnableFeignClients(clients = InventoryServiceFeignClient.class)` +[[attribute-resolution-mode]] +==== Attribute resolution mode + +While creating `Feign` client beans, we resolve the values passed via the `@FeignClient` annotation. As of `4.x`, the values are being resolved eagerly. This is a good solution for most use-cases, and it also allows for AOT support. + +If you need the attributes to be resolved lazily, set the `spring.cloud.openfeign.lazy-attributes-resolution` property value to `true`. + +TIP: For Spring Cloud Contract test integration, lazy attribute resolution should be used. + [[spring-cloud-feign-overriding-defaults]] === Overriding Feign Defaults @@ -905,6 +914,17 @@ The URL provided in the configuration properties remains unused. |=== +=== AOT and Native Image Support + +Spring Cloud OpenFeign supports Spring AOT transformations and native images, however, only with refresh mode disabled, Feign clients refresh disabled (default setting) and <> disabled (default setting). + +WARNING: If you want to run Spring Cloud OpenFeign clients in AOT or native image modes, make sure to set `spring.cloud.refresh.enabled` to `false`. + +TIP: If you want to run Spring Cloud OpenFeign clients in AOT or native image modes, ensure `spring.cloud.openfeign.client.refresh-enabled` has not been set to `true`. + +TIP: If you want to run Spring Cloud OpenFeign clients in AOT or native image modes, ensure `spring.cloud.openfeign.lazy-attributes-resolution` has not been set to `true`. + + == Configuration properties To see the list of all Spring Cloud OpenFeign related configuration properties please check link:appendix.html[the Appendix page]. diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientSpecification.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientSpecification.java index 6a8abd82..345ad8b0 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientSpecification.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientSpecification.java @@ -24,6 +24,7 @@ import org.springframework.cloud.context.named.NamedContextFactory; /** * @author Dave Syer * @author Gregor Zurowski + * @author Olga Maciaszek-Sharma */ public class FeignClientSpecification implements NamedContextFactory.Specification { diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java index 6c658b78..d0cdde94 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java @@ -206,7 +206,6 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLo private void registerFeignClient(BeanDefinitionRegistry registry, AnnotationMetadata annotationMetadata, Map attributes) { String className = annotationMetadata.getClassName(); - // TODO: document change and correct AOT and contract usage if (String.valueOf(false).equals( environment.getProperty("spring.cloud.openfeign.lazy-attributes-resolution", String.valueOf(false)))) { eagerlyRegisterFeignClientBeanDefinition(className, attributes, registry); diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/aot/FeignClientBeanFactoryInitializationAotProcessor.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/aot/FeignClientBeanFactoryInitializationAotProcessor.java index ff32f5ba..3e599537 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/aot/FeignClientBeanFactoryInitializationAotProcessor.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/aot/FeignClientBeanFactoryInitializationAotProcessor.java @@ -52,7 +52,12 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; /** + * A {@link BeanFactoryInitializationAotProcessor} that creates an + * {@link BeanFactoryInitializationAotContribution} that registers bean definitions and + * proxy hints for Feign client beans. + * * @author Olga Maciaszek-Sharma + * @since 4.0.0 */ public class FeignClientBeanFactoryInitializationAotProcessor implements BeanRegistrationExcludeFilter, BeanFactoryInitializationAotProcessor { diff --git a/spring-cloud-openfeign-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-openfeign-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 8e90d1bd..6b9c671d 100644 --- a/spring-cloud-openfeign-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-openfeign-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -79,6 +79,12 @@ "type": "java.lang.String", "description": "Provides a clientId to be used with OAuth2.", "defaultValue": "" + }, + { + "name": "spring.cloud.openfeign.lazy-attributes-resolution", + "type": "java.lang.Boolean", + "description": "Switches @FeignClient attributes resolution mode to lazy.", + "defaultValue": "false" } ] } diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/aot/FeignAotTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/aot/FeignAotTests.java index f262b946..34c2d8f8 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/aot/FeignAotTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/aot/FeignAotTests.java @@ -55,7 +55,7 @@ import org.springframework.web.bind.annotation.GetMapping; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link FeignChildContextInitializer}. + * AOT processing tests. * * @author Olga Maciaszek-Sharma */