From 7f01fdbfe5f287c28e33860f8f59feb47812ecea Mon Sep 17 00:00:00 2001 From: Kurok1 Date: Thu, 16 Jan 2025 21:11:25 +0800 Subject: [PATCH 1/2] allow feign load component from main application-context --- .../openfeign/FeignComponentProvider.java | 37 ++++++++++++++++++ ...ignClientAutoRefreshAutoConfiguration.java | 10 ++++- .../autorefresh/AutoRefreshCapability.java | 39 +++++++------------ ...ignClientConfigurationChangedListener.java | 4 +- .../components/DecoratedContract.java | 6 +-- .../components/DecoratedDecoder.java | 6 +-- .../components/DecoratedEncoder.java | 6 +-- .../components/DecoratedErrorDecoder.java | 6 +-- .../components/DecoratedFeignComponent.java | 23 +++++------ .../components/DecoratedQueryMapEncoder.java | 6 +-- .../components/DecoratedRetryer.java | 6 +-- ...ot.autoconfigure.AutoConfiguration.imports | 0 .../spring/cloud/openfeign/BaseTest.java | 5 --- .../RequestInterceptorChangedTest.java | 5 +-- 14 files changed, 94 insertions(+), 65 deletions(-) create mode 100644 microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/FeignComponentProvider.java rename microsphere-spring-cloud-openfeign/src/main/resources/META-INF/{ => spring}/org.springframework.boot.autoconfigure.AutoConfiguration.imports (100%) diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/FeignComponentProvider.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/FeignComponentProvider.java new file mode 100644 index 0000000..3b204d5 --- /dev/null +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/FeignComponentProvider.java @@ -0,0 +1,37 @@ +package io.microsphere.spring.cloud.openfeign; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; +import org.springframework.cloud.context.named.NamedContextFactory; +import org.springframework.cloud.openfeign.FeignClientSpecification; + +/** + * @author 韩超 + * @since 0.0.1 + */ +public class FeignComponentProvider implements BeanFactoryAware { + + private final NamedContextFactory contextFactory; + + private BeanFactory mainBeanFactory; + + public FeignComponentProvider(NamedContextFactory contextFactory) { + this.contextFactory = contextFactory; + } + + public T getInstance(String contextName, Class type) { + T component = this.contextFactory.getInstance(contextName, type); + if (component == null && mainBeanFactory instanceof AutowireCapableBeanFactory) { + //create new + return ((AutowireCapableBeanFactory)this.mainBeanFactory).createBean(type); + } + return component; + } + + @Override + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.mainBeanFactory = beanFactory; + } +} diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/FeignClientAutoRefreshAutoConfiguration.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/FeignClientAutoRefreshAutoConfiguration.java index 93c5e36..d6c8fbb 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/FeignClientAutoRefreshAutoConfiguration.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/FeignClientAutoRefreshAutoConfiguration.java @@ -1,5 +1,6 @@ package io.microsphere.spring.cloud.openfeign.autoconfigure; +import io.microsphere.spring.cloud.openfeign.FeignComponentProvider; import io.microsphere.spring.cloud.openfeign.autorefresh.FeignClientConfigurationChangedListener; import io.microsphere.spring.cloud.openfeign.autorefresh.FeignComponentRegistry; import io.microsphere.spring.cloud.openfeign.components.NoOpRequestInterceptor; @@ -7,8 +8,10 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration; +import org.springframework.cloud.context.named.NamedContextFactory; import org.springframework.cloud.openfeign.FeignBuilderCustomizer; import org.springframework.cloud.openfeign.FeignClientProperties; +import org.springframework.cloud.openfeign.FeignClientSpecification; import org.springframework.context.annotation.Bean; /** @@ -20,7 +23,7 @@ * @since 0.0.1 */ @ConditionalOnBean(EnableFeignAutoRefresh.Marker.class) -@AutoConfigureAfter(ConfigurationPropertiesRebinderAutoConfiguration.class) +//@AutoConfigureAfter(ConfigurationPropertiesRebinderAutoConfiguration.class) public class FeignClientAutoRefreshAutoConfiguration { @Bean @@ -45,4 +48,9 @@ public FeignClientSpecificationPostProcessor feignClientSpecificationPostProcess return new FeignClientSpecificationPostProcessor(); } + @Bean + public FeignComponentProvider feignComponentProvider(NamedContextFactory contextFactory) { + return new FeignComponentProvider(contextFactory); + } + } diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/AutoRefreshCapability.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/AutoRefreshCapability.java index 599ea4d..f18ace6 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/AutoRefreshCapability.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/AutoRefreshCapability.java @@ -1,22 +1,12 @@ package io.microsphere.spring.cloud.openfeign.autorefresh; -import feign.Capability; -import feign.Contract; -import feign.QueryMapEncoder; -import feign.RequestInterceptor; -import feign.Retryer; +import feign.*; import feign.codec.Decoder; import feign.codec.Encoder; import feign.codec.ErrorDecoder; -import io.microsphere.spring.cloud.openfeign.components.DecoratedContract; -import io.microsphere.spring.cloud.openfeign.components.DecoratedDecoder; -import io.microsphere.spring.cloud.openfeign.components.DecoratedEncoder; -import io.microsphere.spring.cloud.openfeign.components.DecoratedErrorDecoder; -import io.microsphere.spring.cloud.openfeign.components.DecoratedFeignComponent; -import io.microsphere.spring.cloud.openfeign.components.DecoratedQueryMapEncoder; -import io.microsphere.spring.cloud.openfeign.components.DecoratedRetryer; +import io.microsphere.spring.cloud.openfeign.FeignComponentProvider; +import io.microsphere.spring.cloud.openfeign.components.*; import org.springframework.beans.BeansException; -import org.springframework.cloud.openfeign.FeignClientFactory; import org.springframework.cloud.openfeign.FeignClientProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -28,22 +18,21 @@ public class AutoRefreshCapability implements Capability, ApplicationContextAware { private final FeignComponentRegistry componentRegistry; - private final FeignClientFactory feignClientFactory; + //private final FeignClientFactory feignClientFactory; + private final FeignComponentProvider componentProvider; private final FeignClientProperties clientProperties; private String contextId; - private static final String CONTEXT_ID_PROPERTY_NAME = "feign.client.name"; - - public AutoRefreshCapability(FeignClientProperties clientProperties, FeignClientFactory feignClientFactory, FeignComponentRegistry componentRegistry) { + public AutoRefreshCapability(FeignClientProperties clientProperties, FeignComponentProvider componentProvider, FeignComponentRegistry componentRegistry) { this.clientProperties = clientProperties; - this.feignClientFactory = feignClientFactory; + this.componentProvider = componentProvider; this.componentRegistry = componentRegistry; } @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.contextId = applicationContext.getEnvironment().getProperty(CONTEXT_ID_PROPERTY_NAME); + this.contextId = applicationContext.getEnvironment().getProperty("spring.cloud.openfeign.client.name"); } @@ -53,7 +42,7 @@ public Retryer enrich(Retryer retryer) { return null; DecoratedRetryer decoratedRetryer = DecoratedFeignComponent.instantiate(DecoratedRetryer.class, Retryer.class, - contextId, feignClientFactory, clientProperties, retryer); + contextId, componentProvider, clientProperties, retryer); this.componentRegistry.register(contextId, decoratedRetryer); return decoratedRetryer; @@ -65,7 +54,7 @@ public Contract enrich(Contract contract) { return null; DecoratedContract decoratedContract = DecoratedFeignComponent.instantiate(DecoratedContract.class, Contract.class, - contextId, feignClientFactory, clientProperties, contract); + contextId, componentProvider, clientProperties, contract); this.componentRegistry.register(contextId, decoratedContract); return decoratedContract; } @@ -76,7 +65,7 @@ public Decoder enrich(Decoder decoder) { return null; DecoratedDecoder decoratedDecoder = DecoratedFeignComponent.instantiate(DecoratedDecoder.class, Decoder.class, - contextId, feignClientFactory, clientProperties, decoder); + contextId, componentProvider, clientProperties, decoder); this.componentRegistry.register(contextId, decoratedDecoder); return decoratedDecoder; } @@ -87,7 +76,7 @@ public Encoder enrich(Encoder encoder) { return null; DecoratedEncoder decoratedEncoder = DecoratedFeignComponent.instantiate(DecoratedEncoder.class, Encoder.class, - contextId, feignClientFactory, clientProperties, encoder); + contextId, componentProvider, clientProperties, encoder); this.componentRegistry.register(contextId, decoratedEncoder); return decoratedEncoder; } @@ -97,7 +86,7 @@ public ErrorDecoder enrich(ErrorDecoder decoder) { return null; DecoratedErrorDecoder decoratedErrorDecoder = DecoratedFeignComponent.instantiate(DecoratedErrorDecoder.class, ErrorDecoder.class, - contextId, feignClientFactory, clientProperties, decoder); + contextId, componentProvider, clientProperties, decoder); this.componentRegistry.register(contextId, decoratedErrorDecoder); return decoratedErrorDecoder; } @@ -113,7 +102,7 @@ public QueryMapEncoder enrich(QueryMapEncoder queryMapEncoder) { return null; DecoratedQueryMapEncoder decoratedQueryMapEncoder = DecoratedFeignComponent.instantiate(DecoratedQueryMapEncoder.class, QueryMapEncoder.class, - contextId, feignClientFactory, clientProperties, queryMapEncoder); + contextId, componentProvider, clientProperties, queryMapEncoder); this.componentRegistry.register(contextId, decoratedQueryMapEncoder); return decoratedQueryMapEncoder; diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/FeignClientConfigurationChangedListener.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/FeignClientConfigurationChangedListener.java index c4cede8..b4d8ed2 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/FeignClientConfigurationChangedListener.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autorefresh/FeignClientConfigurationChangedListener.java @@ -19,7 +19,9 @@ public FeignClientConfigurationChangedListener(FeignComponentRegistry registry) this.registry = registry; } - private final String PREFIX = "feign.client.config."; + private final String PREFIX = "spring.cloud.openfeign.client.config."; + + @Override public void onApplicationEvent(EnvironmentChangeEvent event) { diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedContract.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedContract.java index 2f489a0..05eee3d 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedContract.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedContract.java @@ -2,7 +2,7 @@ import feign.Contract; import feign.MethodMetadata; -import org.springframework.cloud.openfeign.FeignClientFactory; +import io.microsphere.spring.cloud.openfeign.FeignComponentProvider; import org.springframework.cloud.openfeign.FeignClientProperties; import java.util.List; @@ -13,8 +13,8 @@ */ public class DecoratedContract extends DecoratedFeignComponent implements Contract { - public DecoratedContract(String contextId, FeignClientFactory feignClientFactory, FeignClientProperties clientProperties, Contract delegate) { - super(contextId, feignClientFactory, clientProperties, delegate); + public DecoratedContract(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, Contract delegate) { + super(contextId, feignComponentProvider, clientProperties, delegate); } @Override diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedDecoder.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedDecoder.java index 1da204c..91da63d 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedDecoder.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedDecoder.java @@ -4,7 +4,7 @@ import feign.Response; import feign.codec.DecodeException; import feign.codec.Decoder; -import org.springframework.cloud.openfeign.FeignClientFactory; +import io.microsphere.spring.cloud.openfeign.FeignComponentProvider; import org.springframework.cloud.openfeign.FeignClientProperties; import java.io.IOException; @@ -16,8 +16,8 @@ */ public class DecoratedDecoder extends DecoratedFeignComponent implements Decoder { - public DecoratedDecoder(String contextId, FeignClientFactory feignClientFactory, FeignClientProperties clientProperties, Decoder delegate) { - super(contextId, feignClientFactory, clientProperties, delegate); + public DecoratedDecoder(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, Decoder delegate) { + super(contextId, feignComponentProvider, clientProperties, delegate); } @Override diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedEncoder.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedEncoder.java index 2825630..3ef7a3b 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedEncoder.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedEncoder.java @@ -3,7 +3,7 @@ import feign.RequestTemplate; import feign.codec.EncodeException; import feign.codec.Encoder; -import org.springframework.cloud.openfeign.FeignClientFactory; +import io.microsphere.spring.cloud.openfeign.FeignComponentProvider; import org.springframework.cloud.openfeign.FeignClientProperties; import java.lang.reflect.Type; @@ -14,8 +14,8 @@ */ public class DecoratedEncoder extends DecoratedFeignComponent implements Encoder { - public DecoratedEncoder(String contextId, FeignClientFactory feignClientFactory, FeignClientProperties clientProperties, Encoder delegate) { - super(contextId, feignClientFactory, clientProperties, delegate); + public DecoratedEncoder(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, Encoder delegate) { + super(contextId, feignComponentProvider, clientProperties, delegate); } @Override diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedErrorDecoder.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedErrorDecoder.java index 326daf5..9876660 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedErrorDecoder.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedErrorDecoder.java @@ -2,7 +2,7 @@ import feign.Response; import feign.codec.ErrorDecoder; -import org.springframework.cloud.openfeign.FeignClientFactory; +import io.microsphere.spring.cloud.openfeign.FeignComponentProvider; import org.springframework.cloud.openfeign.FeignClientProperties; /** @@ -11,8 +11,8 @@ */ public class DecoratedErrorDecoder extends DecoratedFeignComponent implements ErrorDecoder { - public DecoratedErrorDecoder(String contextId, FeignClientFactory feignClientFactory, FeignClientProperties clientProperties, ErrorDecoder delegate) { - super(contextId, feignClientFactory, clientProperties, delegate); + public DecoratedErrorDecoder(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, ErrorDecoder delegate) { + super(contextId, feignComponentProvider, clientProperties, delegate); } @Override diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedFeignComponent.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedFeignComponent.java index 0303098..aeb65b6 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedFeignComponent.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedFeignComponent.java @@ -1,10 +1,10 @@ package io.microsphere.spring.cloud.openfeign.components; +import io.microsphere.spring.cloud.openfeign.FeignComponentProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; -import org.springframework.cloud.openfeign.FeignClientFactory; import org.springframework.cloud.openfeign.FeignClientProperties; import org.springframework.lang.NonNull; @@ -19,7 +19,8 @@ public abstract class DecoratedFeignComponent implements Refreshable { private final Logger log = LoggerFactory.getLogger(getClass()); - private final FeignClientFactory feignClientFactory; + //private final FeignClientFactory feignClientFactory; + private final FeignComponentProvider componentProvider; private final String contextId; private final FeignClientProperties clientProperties; @@ -32,9 +33,9 @@ public abstract class DecoratedFeignComponent implements Refreshable { private final ReentrantReadWriteLock.ReadLock readLock = lock.readLock(); private final ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock(); - public DecoratedFeignComponent(String contextId, FeignClientFactory feignClientFactory, FeignClientProperties clientProperties, T delegate) { + public DecoratedFeignComponent(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, T delegate) { this.contextId = contextId; - this.feignClientFactory = feignClientFactory; + this.componentProvider = feignComponentProvider; this.clientProperties = clientProperties; this.delegate = delegate; } @@ -52,9 +53,9 @@ public T delegate() { } @NonNull - public FeignClientFactory getFeignClientFactory() { - return this.feignClientFactory; - } + public FeignComponentProvider getFeignComponentProvider() { + return this.componentProvider; + }; @NonNull public String contextId() { @@ -83,7 +84,7 @@ protected T loadInstance() { String contextId = contextId(); writeLock.lock(); try { - T component = getFeignClientFactory().getInstance(contextId, componentType); + T component = getFeignComponentProvider().getInstance(contextId, componentType); if (component == null) component = BeanUtils.instantiateClass(componentType); this.delegate = component; @@ -112,10 +113,10 @@ public String toString() { } public static , T> W instantiate(Class decoratedClass, Class componentClass, - String contextId, FeignClientFactory feignClientFactory, FeignClientProperties clientProperties, T delegate) { + String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, T delegate) { try { - Constructor constructor = decoratedClass.getConstructor(String.class, FeignClientFactory.class, FeignClientProperties.class, componentClass); - return BeanUtils.instantiateClass(constructor, contextId, feignClientFactory, clientProperties, delegate); + Constructor constructor = decoratedClass.getConstructor(String.class, FeignComponentProvider.class, FeignClientProperties.class, componentClass); + return BeanUtils.instantiateClass(constructor, contextId, feignComponentProvider, clientProperties, delegate); } catch (NoSuchMethodException noSuchMethodException) { throw new BeanInstantiationException(decoratedClass, noSuchMethodException.getLocalizedMessage()); } diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedQueryMapEncoder.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedQueryMapEncoder.java index 8bf0d75..6e4d941 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedQueryMapEncoder.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/components/DecoratedQueryMapEncoder.java @@ -2,7 +2,7 @@ import feign.QueryMapEncoder; import io.microsphere.logging.Logger; -import org.springframework.cloud.openfeign.FeignClientFactory; +import io.microsphere.spring.cloud.openfeign.FeignComponentProvider; import org.springframework.cloud.openfeign.FeignClientProperties; import java.lang.invoke.MethodHandle; @@ -23,8 +23,8 @@ public class DecoratedQueryMapEncoder extends DecoratedFeignComponent implements Retryer { - public DecoratedRetryer(String contextId, FeignClientFactory feignClientFactory, FeignClientProperties clientProperties, Retryer delegate) { - super(contextId, feignClientFactory, clientProperties, delegate); + public DecoratedRetryer(String contextId, FeignComponentProvider feignComponentProvider, FeignClientProperties clientProperties, Retryer delegate) { + super(contextId, feignComponentProvider, clientProperties, delegate); } @Override diff --git a/microsphere-spring-cloud-openfeign/src/main/resources/META-INF/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/microsphere-spring-cloud-openfeign/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports similarity index 100% rename from microsphere-spring-cloud-openfeign/src/main/resources/META-INF/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename to microsphere-spring-cloud-openfeign/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseTest.java index 49f7734..c21b1f6 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/BaseTest.java @@ -5,9 +5,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration; import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.cloud.endpoint.event.RefreshEvent; import org.springframework.cloud.openfeign.EnableFeignClients; @@ -38,7 +35,6 @@ @ComponentScan(basePackages = "io.microsphere.spring.cloud.openfeign") @EnableFeignClients(clients = BaseClient.class) @EnableFeignAutoRefresh -@AutoConfigureAfter(ConfigurationPropertiesRebinderAutoConfiguration.class) public abstract class BaseTest { private static final Logger log = LoggerFactory.getLogger(BaseTest.class); @@ -73,7 +69,6 @@ public void replaceConfig() { public void testInternal() { try { this.client.echo("hello", "1.0"); - } catch (Exception ignored) { } diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorChangedTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorChangedTest.java index 870b94a..f9651f1 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorChangedTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/requestInterceptor/RequestInterceptorChangedTest.java @@ -2,11 +2,8 @@ import feign.RequestInterceptor; import io.microsphere.spring.cloud.openfeign.BaseTest; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; /** * @author 韩超 @@ -18,7 +15,7 @@ public class RequestInterceptorChangedTest extends BaseTest @Override protected String afterTestComponentConfigKey() { - return "feign.client.config.my-client.request-interceptors[0]"; + return "spring.cloud.openfeign.client.config.my-client.request-interceptors[0]"; } @Override From 4986f5086802360104d0ef91f0d3886433c2cf9c Mon Sep 17 00:00:00 2001 From: Kurok1 Date: Thu, 16 Jan 2025 21:11:48 +0800 Subject: [PATCH 2/2] test config change --- .../spring/cloud/openfeign/encoder/EncoderChangedTest.java | 2 +- .../cloud/openfeign/errordecoder/ErrorDecoderChangedTest.java | 2 +- .../openfeign/querymapencoder/QueryMapEncoderChangedTest.java | 2 +- .../spring/cloud/openfeign/retryer/RetryerChangedTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderChangedTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderChangedTest.java index 938ea9f..7989641 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderChangedTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/encoder/EncoderChangedTest.java @@ -15,7 +15,7 @@ public class EncoderChangedTest extends BaseTest { @Override protected String afterTestComponentConfigKey() { - return "feign.client.config.my-client.encoder"; + return "spring.cloud.openfeign.client.config.my-client.encoder"; } @Override diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderChangedTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderChangedTest.java index e431c1f..79a2e1b 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderChangedTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/errordecoder/ErrorDecoderChangedTest.java @@ -15,7 +15,7 @@ public class ErrorDecoderChangedTest extends BaseTest { @Override protected String afterTestComponentConfigKey() { - return "feign.client.config.my-client.error-decoder"; + return "spring.cloud.openfeign.client.config.my-client.error-decoder"; } @Override diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderChangedTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderChangedTest.java index 69928a6..14f9ba8 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderChangedTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/querymapencoder/QueryMapEncoderChangedTest.java @@ -15,7 +15,7 @@ public class QueryMapEncoderChangedTest extends BaseTest { @Override protected String afterTestComponentConfigKey() { - return "feign.client.config.my-client.query-map-encoder"; + return "spring.cloud.openfeign.client.config.my-client.query-map-encoder"; } @Override diff --git a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerChangedTest.java b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerChangedTest.java index 5c66d25..5139dfc 100644 --- a/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerChangedTest.java +++ b/microsphere-spring-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/retryer/RetryerChangedTest.java @@ -15,7 +15,7 @@ public class RetryerChangedTest extends BaseTest { @Override protected String afterTestComponentConfigKey() { - return "feign.client.config.my-client.retryer"; + return "spring.cloud.openfeign.client.config.my-client.retryer"; } @Override