我是靠谱客的博主 明亮眼神,最近开发中收集的这篇文章主要介绍使用@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 标注多个类指定统一微服务时,报错A bean with that name has already been defined所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复