Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyblitz committed Jan 16, 2025
1 parent ae858d3 commit 931dfa2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
import io.microsphere.spring.cloud.openfeign.components.NoOpRequestInterceptor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration;
import org.springframework.cloud.openfeign.FeignBuilderCustomizer;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;

/**
* The Auto-Configuration class for {@link EnableFeignAutoRefresh}
Expand All @@ -20,7 +25,6 @@
* @since 0.0.1
*/
@ConditionalOnBean(EnableFeignAutoRefresh.Marker.class)
@AutoConfigureAfter(ConfigurationPropertiesRebinderAutoConfiguration.class)
public class FeignClientAutoRefreshAutoConfiguration {

@Bean
Expand All @@ -30,9 +34,12 @@ public FeignBuilderCustomizer addDefaultRequestInterceptorCustomizer() {
};
}

@Bean
public FeignClientConfigurationChangedListener feignClientConfigurationChangedListener(FeignComponentRegistry registry) {
return new FeignClientConfigurationChangedListener(registry);
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReadyEvent(ApplicationReadyEvent event) {
/**
* Make sure the FeignClientConfigurationChangedListener is registered after the ConfigurationPropertiesRebinder
*/
registerFeignClientConfigurationChangedListener(event);
}

@Bean
Expand All @@ -45,4 +52,10 @@ public FeignClientSpecificationPostProcessor feignClientSpecificationPostProcess
return new FeignClientSpecificationPostProcessor();
}

private void registerFeignClientConfigurationChangedListener(ApplicationReadyEvent event) {
ConfigurableApplicationContext context = event.getApplicationContext();
FeignComponentRegistry feignComponentRegistry = context.getBean(FeignComponentRegistry.class);
context.addApplicationListener(new FeignClientConfigurationChangedListener(feignComponentRegistry));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public FeignClientConfigurationChangedListener(FeignComponentRegistry registry)
@Override
public void onApplicationEvent(EnvironmentChangeEvent event) {
Map<String, Set<String>> effectiveClients = resolveChangedClient(event);
effectiveClients.forEach(registry::refresh);
if (!effectiveClients.isEmpty()) {
effectiveClients.forEach(registry::refresh);
}
}

protected Map<String, Set<String>> resolveChangedClient(EnvironmentChangeEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
@ComponentScan(basePackages = "io.microsphere.spring.cloud.openfeign")
@EnableFeignClients(clients = BaseClient.class)
@EnableFeignAutoRefresh
@AutoConfigureAfter(ConfigurationPropertiesRebinderAutoConfiguration.class)
public abstract class BaseTest<T> {

private static final Logger log = LoggerFactory.getLogger(BaseTest.class);
Expand Down

0 comments on commit 931dfa2

Please sign in to comment.