Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the solution to the @ feignclient name conflict

Shulou Source: shulou.com Published: 2022-06-03 02:02:04 10月24日 Update

Today, I would like to talk to you about the solution to the @ feignclient name conflict. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.

@ feignclient name conflict

Encountered when starting the springcloud project

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

Such an exception

After research, the solution is as follows

1. Add configuration to the configuration file

Spring.main.allow-bean-definition-overriding=true

2. Add a field to the feignclient comment, the red part

@ FeignClient (value = "provider-demo3-ribbon", path = "/ dev", contextId= "tt1") @ FeignClient the same name, multiple configuration classes

The version of spring-cloud-starter-openfeign I use is 2.0.0, and then when I use @ FeignClient, I can't name more than one configuration class. Later, I also found all kinds of netizens from the network, anyway, there are all kinds of crooked ways. But the method given by the official website is more reliable.

Solution

1. Add configuration

Spring.main.allow-bean-definition-overriding=true

2. This allows bean with the same name to exist, but it is not safe and is not recommended. (from network, untested) A new attribute ContextId has been added to @ FeignClient in openfeign version 2.2.1, so it is possible to use this attribute. This routine is available on the official website.

3. Another method provided on the official website is to create a Feign client manually, as follows. (official website)

@ Import (FeignClientsConfiguration.class) class FooController {private FooClient fooClient; private FooClient adminClient @ Autowired public FooController (Decoder decoder, Encoder encoder, Client client, Contract contract) {this.fooClient = Feign.builder () .client (client) .encoder (encoder) .decoder (decoder) .contract (contract) .requestInterceptor (new BasicAuthRequestInterceptor ("user", "user")) .target (FooClient.class, "https://PROD-SVC");") This.adminClient = Feign.builder (). Client (client) .encoder (encoder) .decoder (decoder) .contract (contract) .requestInterceptor (new BasicAuthRequestInterceptor ("admin", "admin")) .target (FooClient.class, "https://PROD-SVC");") }} after reading the above, do you have any further understanding of the solution to the @ feignclient name conflict? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Configuration name solution conflict content that is method multiple property version network security crooked field customer client manual file time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MySQL Microsoft NVidia Huawei