首页 > 其他分享 >openFeign调用问题:required a bean of type 'xxx' that could not be found.

openFeign调用问题:required a bean of type 'xxx' that could not be found.

时间:2024-07-19 18:21:07浏览次数:9  
标签:Feign 服务 openFeign could required springframework testA testB com

场景:

服务B是一个公共的服务,打包成jar后给其他服务使用

package com.testB.seviceB.remote;
//服务B中定义的feign接口
@FeignClient(value = "service-c", path = "/service-c")
public interface ServiceBClient {
    xxxx
}

 

服务A中引用服务B中定义的Feign接口

package com.testA.serviceA.service;
@Service
public class CallServcieB {
    //引用服务B中的Feign接口
    @Autowired
    private ServiceBClient serviceBClient;
​
}
 

启动服务A 是报错:声明的 ServiceBClient 找不到

2024-07-19 17:39:58.008 ERROR 47544 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
​
***************************
​
APPLICATION FAILED TO START
​
***************************
​
Description:
​
Field serviceBClient in com.testA.serviceA.service.CallServcieB required a bean of type 'com.testB.seviceB.remote.ServiceBClient' that could not be found.
​
The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)
​
​
Action:
​
Consider defining a bean of type 'com.testB.seviceB.remote.ServiceBClient' in your configuration.

报错原因: 

上面的报错是因为,启动类中Feign默认扫描的是当前服务A的包,需要将引用的服务B的类所在包的路径,也加入Feign的扫描路径中

 

解决:

修改启动类上Feign的扫描路径,将服务B的中的Feign路径加进来,这样就可以识别到引入的服务B的接口了。

com.testA.serviceA 是服务A的路径
com.testB.seviceB.remote  是服务B的Feign接口路径
package com.testA.serviceA;
​
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
​
@EnableDiscoveryClient
//加入引用的包路径
@EnableFeignClients(basePackages = {"com.testA.serviceA", "com.testB.seviceB.remote"})
@SpringBootApplication
public class ServiceAApplication {
​
    public static void main(String[] args) {
        SpringApplication.run(ServiceAApplication.class, args);
    }
​
}

 

 

标签:Feign,服务,openFeign,could,required,springframework,testA,testB,com
From: https://www.cnblogs.com/etangyushan/p/18312085

相关文章

  • OpenFeign调用
    bug01:在其他模块调用找不到bean时,在api模块org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.hmall.api.client.UserClient\4.1.1.引入依赖在cart-service服务的pom.xml中引入OpenFeign的依赖和loadBalancer依赖:<!--openFeign--><dependency......
  • 解决Could not find artifact jdk.tools:jdk.tools:jar:1.8 at specified
    报错详细信息Failedtoexecutegoalorg.apache.maven.plugins:maven-dependency-plugin:3.1.1:tree(default-cli)onprojectspringbootbd-product:Cannotbuildprojectdependencygraph:Couldnotresolvenorcollectfollowingdependencies:[jdk.tools:jdk.tools:ja......
  • Spring Cloud Alibaba——OpenFeign
            OpenFeign是一个显示声明式的WebService客户端。使用OpenFeign能让编写WebService客户端更加简单。使用时只需定义服务接口,然后在上面添加注解。OpenFeign也支持可拔插式的编码和解码器。Springcloud对feign进行了封装,使其支持MVC注解和HttpMessageConverts......
  • 一分钟解决CLIENT_PLUGIN_AUTH is required. IDEA连接数据库时报错
    CLIENT_PLUGIN_AUTHisrequired.IDEA连接数据库时报错​ 今天楼主在导入java项目时在连接数据库时IDEA报的错误为CLIENT_PLUGIN_AUTHisrequired.​ 报错如下图:经过多方排查,发现是之前下载过其他数据库,导致系统服务里已经启动了一个MySql服务​ 已经安装过小蜜蜂数据库,我......
  • OpenFeign实现微服务远程调用
    跟着黑马微服务课程走的,是思路1,把不同服务的方法统一抽到一个公共模块中在微服务中,如果一个服务需要请求另一个服务的接口,那么就会涉及到发起远程请求,但是手动发请求太麻烦,OpenFeign提供了基于接口的声明式REST客户端,让开发者可以通过编写接口的方式来定义服务间的调......
  • OpenFeign 使用细节
    @FeignClient注解配置项public@interfaceFeignClient{//和value互为别名,标示要调用哪个服务,要和nacos上面的服务名一致@AliasFor("name")Stringvalue()default"";//当服务提供者的接口太多了,调用方想分为多个FeignClient,就要指定不同的......
  • OpenFeign 服务调用与负载
    需要建两个工程,一个是服务提供者,一个是服务调用者服务提供者一个普通的nacos服务,增加一个controller方法即可,上一篇文章刚说了,这里简单说下<!--服务提供者不调用其他服务,所以只需要注册到nacos的依赖--><dependency><groupId>com.alibaba.cloud</groupId><a......
  • KEIL出现error: L6002U: Could not open file ...报错
     在对MSPM0L1306进行工程移植时,依照参考方法更新头文件路径后出现一个报错:.\Objects\empty_LP_MSPM0L1306_nortos_keil.axf:error:L6002U:Couldnotopenfile../../../../../../source/ti/driverlib/lib/keil/m0p/mspm0l11xx_l13xx/driverlib.a:Nosuchfileordirec......
  • MySQL 主从报错“Got fatal error 1236 from master when reading data from binary l
    1、背景一主一从报错,测试环境从库执行showslavestatus\Gmysql>showslavestatus\G***************************1.row***************************Slave_IO_State:Master_Host:10.0.0.51Master_User:repl......
  • mac m3 pro : Could not initialize class com.sun.jna.Native
    java.lang.NoClassDefFoundError:Couldnotinitializeclasscom.sun.jna.Nativejava.lang.UnsatisfiedLinkError:/Users/wang/Library/Caches/JNA/temp/jna2072012754992384454.tmp:dlopen(/Users/wang/Library/Caches/JNA/temp/jna2072012754992384454.tmp,0x0001):......