The bean ‘xxx.FeignClientSpecification‘ could not be registered. A bean with that name has already b

这篇具有很好参考价值的文章主要介绍了The bean ‘xxx.FeignClientSpecification‘ could not be registered. A bean with that name has already b。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、异常日志:

The bean 'xxxx.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

二、原因:
在同于一个微服务中多个feign接口使用@FeignClient注解调用同一个名称的微服务,启动时引发的异常
比如:项目中定义了两个feign接口类,但是注解都是@FeignClient(value = "userinfo-service")为此报错了。

@Component
@FeignClient(value = "base-log")
public interface LogReqFeign {

    @PostMapping("/v1/base/log/req")
    ResObj postObj(@RequestBody ReqObj<LogReq> reqObj);

    @GetMapping("/v1/base/log/req")
    ResObj getObj(Map<String, Object> map);

    @GetMapping("/v1/base/log/req/{id}")
    ResObj getObjById(@PathVariable("id") Long id);
    
}
@Component
@FeignClient(value = "base-log")
public interface LogEventFeign {

    @PostMapping("/v1/base/log/event")
    ResObj postObj(@RequestBody ReqObj<LogEvent> reqObj);

    @GetMapping("/v1/base/log/event")
    ResObj getObj(Map<String, Object> map);

    @GetMapping("/v1/base/log/event/{id}")
    ResObj getObjById(@PathVariable("id") Long id);
}


三、解决方案:
1、方案一:
将调用同一个服务的fegin接口都写到一个LogReqFeign接口类中。但是我这里不合适,我远程调用的方法都是同名的
2、方案二:
配置文件中添加配置:

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

通过设置spring.main.allow-bean-definition-overriding=true来允许bean覆盖,但是这种方式并不推荐,因为可能会导致意外的覆盖,导致应用程序出现其他问题。

3、方案三:

@FeignClient增加contextId属性,改为文章来源地址https://www.toymoban.com/news/detail-588484.html

@FeignClient(name = "xxx", path = API.PATH,contextId="xxx1")
@FeignClient(name = "xxx", path = API.PATH,contextId="xxx2")
@Component
@FeignClient(value = "base-log",contextId = "LogEvent")
public interface LogEventFeign {

    @PostMapping("/v1/base/log/event")
    ResObj postObj(@RequestBody ReqObj<LogEvent> reqObj);

    @GetMapping("/v1/base/log/event")
    ResObj getObj(Map<String, Object> map);

    @GetMapping("/v1/base/log/event/{id}")
    ResObj getObjById(@PathVariable("id") Long id);
}
@Component
@FeignClient(value = "base-log",contextId = "LogReq")
public interface LogReqFeign {

    @PostMapping("/v1/base/log/req")
    ResObj postObj(@RequestBody ReqObj<LogReq> reqObj);

    @GetMapping("/v1/base/log/req")
    ResObj getObj(Map<String, Object> map);

    @GetMapping("/v1/base/log/req/{id}")
    ResObj getObjById(@PathVariable("id") Long id);

}

到了这里,关于The bean ‘xxx.FeignClientSpecification‘ could not be registered. A bean with that name has already b的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • unity error CS0246: The type or namespace name ‘xxx‘ could not be found (are you missing a using

    unity 导入了Bitmap使用后报错: error CS0246: The type or namespace name ‘XXX’ could not be found (are you missing a using directive or an assembly reference?) 解决方案如下: .NET Standard 2.1与 .NET Foundation 发布的 .NET Standard 2.1 配置文件匹配。 Unity 建议新项目使用 .NET Standard 2.1。 它比 .NET 4.x 小,有利于尺

    2024年04月26日
    浏览(29)
  • xcode The document “...“ could not be saved

    Today when I tried to save a file on my project I get an error message saying: The document “nameOfFile.m” could not be saved. I tried reinstalling xcode but no luck. The file can be edited with other editors and I see the same behavior on all my projects as well as newly created projects. Any ideas? 解决:重新启动了 XCode(通过强制退出,而

    2024年02月08日
    浏览(40)
  • @Autowired报错Could not autowire. No beans of ‘XXX‘ type found

      IDEA中使用 @Autowired 报错 Could not autowire. No beans of \\\'XXX\\\' type found ,错误大致意思为:没有匹配到类型为XXX的bean。   个人觉得,注入 controller 的 service 虽然一般来说我们都是注入一个接口,但是该接口有实现类,并且使用 @Service 进行关联,所以注入类型应该也可以视为一

    2024年02月07日
    浏览(35)
  • Qt-解决异常报错“QAxBase::setControl: requested control XXX could not be instantiated”

    作者:翟天保Steven 版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处        使用Qt开发的过程中,QAxObject是经常用到的一个类,用于操作Windows中各种COM接口,进而实现各类功能。        WbemScripting.SWbemLocator是我想要通过QAxObject访问的对

    2024年02月12日
    浏览(30)
  • 解决SpringBoot项目中的报错:Could not autowire,no beans of “XXX“ type found

    问题:找不到mapper注入的bean,如图   分析:注入mapper有两种方式:  第一种:在启动类中添加  @MapperScan        然后在mapper的类中添加  @Repository 注解 第二种方法:直接在各个mapper类中添加@Mapper注解,但是一定要注意导入正确的包,否则解决不了这个异常;  很多新手

    2024年02月08日
    浏览(41)
  • A component required a bean of type ‘...Mapper‘ that could not be found问题解决

    错误如图 第一步 查看配置文件是否正确 第二步 查看标签是否正确 检查UserMapper上是否加上@Mapper 补充 第二步还是不行的话查看下POM文件是否导入mybatis-plus-boot-starter 配置mybatis-plus.mapper-locations无提示信息; 此时发现右上角出现感叹号,Cannot resolve configuration property ‘mybatis-

    2024年02月16日
    浏览(31)
  • 运行springboot出现“A component required a bean of type...that could not be found“问题

    问题 报错信息如下: 大致的意思是:没有找到对应的mapper,需要在你的配置中添加一个mapper类型的bean 解决方法 试了各种方法,后来突然想到,有没有可能是springboot版本的问题,于是打开pom.xml文件,找到parent标签,果然发现默认使用的是3.0.6版本,如下: 但是我之前使用的是

    2024年02月16日
    浏览(36)
  • SpringBoot - 在IDEA中经常发现:Could not autowire. No beans of ‘xxx‘ type found的错误

    错误描述 在SPRINGBOOT的项目中,使用IDEA时经常会遇到Could not autowire. No beans of ‘xxxx’ type found的错误提示,但是程序的编译和运行都没有问题,这个错误提示并不影响项目的生产。 解决方案

    2024年02月15日
    浏览(41)
  • 解决SpringBoot启动失败:A component required a bean of type ‘xxxxxxx‘ that could not be found.

    今天写了一个MD5加密加盐工具类,运用到实际业务代码中缺报错了,内容如下: 根据错误日志不难发现,其实是因为组件没有被找到。因为这个工具类是我自己写的。 然后我就去检查代码,最终发现,我把这个工具类以注解的形式注入进来并使用 但是,这个工具类里面,我

    2024年02月20日
    浏览(34)
  • Springboot启动出现A component required a bean of type ‘com.xxx‘ that could not问题解决

    今日写一个websocket小demo,启动项目时出现错误如下图 检查也没发现漏写注解,思考片刻后突然想起springboot扫描的范围是与启动类同级别的包-就是com.huang.demo.ssm目录下所有注解bean都被扫描,那么ws包里面的bean不在ssm这个路径下,所以导致springboot启动时扫描不到。最后把ws包

    2024年02月11日
    浏览(39)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包