Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the solution to the @ feignclient name conflict

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report