question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot refresh configs in @FeignClient with @RefreshScope

See original GitHub issue

I’m running a Spring Config Server and another Spring boot app that uses config server. I have a Feign-Client in my second app like this:

@FeignClient(url = "${myconfig.url}", name = "ConfigServerFeign",
        configuration = {FeignConfig.class}, fallback = ConfigServerFeignFallback.class)
public interface ConfigServerFeign
{
    @RequestMapping(value = "/test", method = RequestMethod.POST,
            headers = {"Content-Type=application/json; charset=UTF-8"}, consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    RequestModel test(@RequestBody RequestModel request);
}

and i have a config class for feign like this:

@Configuration
public class FeignConfig
{
    @Value("${myconfig.header}")
    private String authorization;
    @Bean
    public RequestInterceptor basicAuthRequestInterceptor()
    {
        return requestTemplate -> requestTemplate.header("Authorization", "Basic " + authorization);
    }
}

i need to change ${myconfig.url} or ${myconfig.header} in runtime. i think i have two option, first one is using @RefreshScope on top of ConfigServerConfig that does not work, the second option is to use @RefreshScope on FeignConfig class that gives me this error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.example.configclient.ConfigServerFeign': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No Scope registered for scope name 'refresh'
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1634) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1316) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1282) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    ... 19 common frames omitted
Caused by: java.lang.IllegalStateException: No Scope registered for scope name 'refresh'
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at org.springframework.cloud.context.named.NamedContextFactory.createContext(NamedContextFactory.java:116) ~[spring-cloud-context-1.2.4.RELEASE.jar:1.2.4.RELEASE]
    at org.springframework.cloud.context.named.NamedContextFactory.getContext(NamedContextFactory.java:85) ~[spring-cloud-context-1.2.4.RELEASE.jar:1.2.4.RELEASE]
    at org.springframework.cloud.context.named.NamedContextFactory.getInstance(NamedContextFactory.java:121) ~[spring-cloud-context-1.2.4.RELEASE.jar:1.2.4.RELEASE]
    at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.get(FeignClientFactoryBean.java:127) ~[spring-cloud-netflix-core-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.feign(FeignClientFactoryBean.java:84) ~[spring-cloud-netflix-core-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:155) ~[spring-cloud-netflix-core-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    ... 29 common frames omitted

how can i fix this ??? 😦

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:27 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
hoseinitcommented, Oct 6, 2020

I am also looking forward for a way to refresh feign when url has been changed and it’s in RefreshScope

2reactions
cens7commented, Aug 14, 2020

I have same question. Two years passed, did this question solved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot refresh configs in @FeignClient with @RefreshScope
I'm running a Spring Config Server and another Spring boot app that uses config server. I have a Feign-Client in my second app...
Read more >
Spring Cloud OpenFeign
Spring @RefreshScope Support. If Feign client refresh is enabled, each feign client is created with feign.Request.Options as a refresh-scoped bean.
Read more >
RefreshScope can't get along with @Bean - Stack Overflow
I have a controller which need refresh config from config server so I add @RefreshScope on it. Meanwhile this controller need to calling...
Read more >
spring cloud config - Refresh scope - YouTube
How to dynamically load values for your application by using Refreshscope annotation.
Read more >
Introduction to Spring Cloud OpenFeign - Baeldung
Configuration. Now, it's very important to understand that each Feign client is composed of a set of customizable components.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found