Tag Archives: Spring #Boot #Cloud #Alibaba

[Solved] Feign Error: -‘oauth-client.FeignClientSpecification‘ could not be registered

environment

<spring-boot.version>2.5.3</spring-boot.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>
<spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>

report errors

Errors are reported during project startup, as follows:

2021-12-22 16:55:56.766  WARN 21922 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'oauth-client.FeignClientSpecification' defined in null: Cannot register bean definition [Generic bean: class [org.springframework.cloud.openfeign.FeignClientSpecification]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'oauth-client.FeignClientSpecification': There is already [Generic bean: class [org.springframework.cloud.openfeign.FeignClientSpecification]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
2021-12-22 16:55:56.776  INFO 21922 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-12-22 16:55:56.799 ERROR 21922 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'xxx-client.FeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

reason

Multiple interfaces in a project use @ feignclient to call the same service, which means that a service can only be used once with @ feignclient.

Solution:

1) Distinguish with ContextID

But I don’t know why it didn’t work

@FeignClient(value = “xxx-server”, contextId = “oauth-client”)
public interface OAuthClientFeignClient {
@GetMapping("/api/v1/oauth-clients/{clientId}")
Result<SysOauthClient> getOAuthClientById(@PathVariable String clientId);
}

2) Add the following code to the application.properties file.

#Allow the existence of multiple Feign calls to the same Service interface
spring.main.allow-bean-definition-overriding=true

3) Add the following code to the application.yml file.

spring:
  main:
    #Allow the existence of multiple Feign calls to the same Service interface
    allow-bean-definition-overriding: true
        The above code enables multiple interfaces to call the same service using @FeignClient.