We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationListener; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component;
@component public class FeignClientEagerLoadConfig implements ApplicationContextAware, BeanDefinitionRegistryPostProcessor, ApplicationListener {
private ApplicationContext applicationContext; private BeanDefinitionRegistry beanDefinitionRegistry; @Override public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } @Override public void postProcessBeanDefinitionRegistry(@NonNull BeanDefinitionRegistry registry) throws BeansException { this.beanDefinitionRegistry = registry; } @Override public void postProcessBeanFactory(@NonNull ConfigurableListableBeanFactory beanFactory) throws BeansException { } @Override public void onApplicationEvent(@NonNull ApplicationStartedEvent event) { CachingSpringLoadBalancerFactory loadBalancerFactory = applicationContext.getBean(CachingSpringLoadBalancerFactory.class); String[] beanNames = applicationContext.getBeanNamesForAnnotation(FeignClient.class); for (String name : beanNames) { Object feignClientNameObj = beanDefinitionRegistry.getBeanDefinition(name).getPropertyValues().get("name"); if (feignClientNameObj != null) { loadBalancerFactory.create(feignClientNameObj.toString()); } } }
}
The text was updated successfully, but these errors were encountered:
我看Spring Cloud TSF Finchley有实现feign eager load,感觉稍微有些复杂。 或许可以用上文的方法?
Sorry, something went wrong.
No branches or pull requests
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
@component
public class FeignClientEagerLoadConfig implements ApplicationContextAware, BeanDefinitionRegistryPostProcessor, ApplicationListener {
}
The text was updated successfully, but these errors were encountered: