我是靠谱客的博主 明亮眼神,这篇文章主要介绍使用@FeignClient 标注多个类指定统一微服务时,报错A bean with that name has already been defined,现在分享给大家,希望可以做个参考。

做spring cloud 远程成调用时,多个类标注调用同一个微服务时:

@FeignClient(name = "${remote.feign.edu-authority-boot.name:edu-authority-boot}", path = "/auth",
fallbackFactory = AuthProviderFallbackFactory.class)
public interface AuthProvider {
@Component
@FeignClient(name = "${remote.feign.edu-authority-boot.name:edu-authority-boot}", path = "/menu",
fallbackFactory = MenuProviderFallbackFactory.class)
public interface MenuProvider {

启动项目时报如下错误:

Description:
The bean '${remote.feign.edu-authority-boot.name:edu-authority-boot}.FeignClientSpecification', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

原因: @FeignClient 注解中的name是指定类型的名称,多个类指定同一个名称就会报错,而这里是要进行远程调用的微服务的名称。

解决方式为,在配置文件中加入如下配置:

spring:
main:
allow-bean-definition-overriding: true

最后

以上就是明亮眼神最近收集整理的关于使用@FeignClient 标注多个类指定统一微服务时,报错A bean with that name has already been defined的全部内容,更多相关使用@FeignClient内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(169)

评论列表共有 0 条评论

立即
投稿
返回
顶部