点击上方 "Java指南者"关注, 星标或置顶一起成长
免费送 1024GB 精品学习资源
来源:https://blog.csdn.net/dtttyc/article/details/109189084
配置 EnableFeignClients之后扫描包报错
class com.yunduo.netty.client.feign.fallback.NettyIMFeignClientFallback found for feign client netty-mode-service
首先错误描述
EnableFeignClients 扫描了 com.yunduo.newbiz.client.feign 包
@EnableDiscoveryClient
com.yunduo.newbiz.client.feign 包下的代码
@FeignClient(
value = "netty-mode-service",
fallbackFactory = NettyIMFeignClientFallback.class
)public interface NettyIMFeignClient {
@RequestMapping(
path = {"/v1/im/{clientId}"},
method = {RequestMethod.POST},
consumes = {"application/json"},
produces = {"application/json"}
)
StatusDTO sendMsg(@PathVariable("clientId") String clientId, @RequestBody Object msg);
}
NettyIMFeignClientFallback 下的代码
@Component
知识点说明
1 SpringBootAppliation 启动时会默认扫描主类及当前包及子包
@SpringBootApplication(scanBasePackages = {
scanBasePackages 扫描指定范围内带注解的@Component, @Controller, @Service, @Repository 等
/**
* Base packages to scan for annotated components. Use {@link #scanBasePackageClasses}
* for a type-safe alternative to String-based package names.
* @return base packages to scan
* @since 1.3.0
*/
2 @EnableFeignClients 注解默认会扫描注解@FeignClient 所在的当前包及子包
@EnableFeignClients(basePackages={
指出报错原因
项目中使用@EnableFeignClients 扫描我们指定的包,但是指定包中使用@Component 和@FeginClint,而@EnableFeignClients 只扫秒@FeignClient,@Component 没有被扫描到,所以会报错。
如何解决
由于项目室 springcloud 项目,需要通过 Feign 调用不同项目接口,所以单独创建一个类,用于扫描包,当然你也可以在@SpringBootApplication 下进行扫描。
/**
* 增加Feign提供端包扫描
*/
热门内容:
两年经验斩获蚂蚁/头条/PingCAP Offer,牛逼了
字节跳动热腾腾的面经分享深入理解 Java 内存模型
关注我
关注我,Java 学习不迷路!
![03fcd34df0576eefbef217161d5c6150.png](https://img-blog.csdnimg.cn/img_convert/03fcd34df0576eefbef217161d5c6150.png)