记录一次异常:feign异常--NoSuchBeanDefinitionException: No qualifying bean of type

news2025/2/27 11:12:23

1、完整报错

2023-06-29 16:17:28.127  WARN 3732 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context 
initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: 

Error creating bean with name 'sysLogAspect': Unsatisfied dependency expressed through field 'remoteSysLogService';
 nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean 
 of type 'cn.ycl.system.api.syslog.feign.RemoteSysLogService' available: expected at least 1 bean which qualifies as autowire candidate.
  Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  
2023-06-29 16:17:28.154  INFO 3732 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-06-29 16:17:28.167  INFO 3732 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-06-29 16:17:28.189 ERROR 3732 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field remoteSysLogService in cn.ycl.syslog.SysLogAspect required a bean of type 'cn.ycl.system.api.syslog.feign.RemoteSysLogService' 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 'cn.ycl.system.api.syslog.feign.RemoteSysLogService' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:63200', transport: 'socket'

Process finished with exit code 1

可以看到异常提示是:NoSuchBeanDefinitionException,报这种错一般就是Spring注入bean实例失败了。

2、我的最终解决方式

在启动类的@EnableFeignClients后面加上包扫描路径,如下:

import com.pig4cloud.pigx.common.feign.annotation.EnablePigxFeignClients;
import com.pig4cloud.pigx.common.security.annotation.EnablePigxResourceServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

/**
 * @author 
 * @date 2023年06月21日 app消息推送服务
 */
@EnablePigxFeignClients
@EnablePigxResourceServer
@EnableDiscoveryClient
@SpringBootApplication
public class LnPushApplication {

	public static void main(String[] args) {
		SpringApplication.run(LnPushApplication.class, args);
	}

}

3、为什么那么久才找到解决办法

如果只有一个启动类中存在@EnableFeignClients注解,那么不需要加basepackage也不会报错并启动成功;

但是一旦有了两个或以上的业务模块作为feign客户端,也就是有两个以上的启动类上存在@EnableFeignClients注解,不加basepackage将报如上错误。


4、没有集成feign时,报此错的解决办法

前面说了,报这种错一般就是Spring注入bean实例失败,所以要么是包扫描路径的问题,比如我遇到的这个问题,以及经典的启动类上没有配置mapper包扫描路径,导致报错XxxMapper类找不到,或者XxxDao类找不到:

要么就是报错的bean上面没有加注解,比如@Service、@Component、@Mapper、@Repository、@Configuration、@RestController等。

看过SpringBoot启动类源码的都知道,Spring boot只会将两种类注入bean容器中:

第一种:要么是在Resource/META-INF/spring.factories文件夹下手动配置的类;
第二种:要么是在启动类所属包下,且被@Component或其派生注解修饰的类(上面提到的注解都是@Component的派生注解)

才会被注入bean容器中。

 

5、集成了openfeign时的其他可能原因
1、feign接口是否定义了实现类,最好添加实现类

2、feign接口实现类上方是否加了@Service注解

3、一般定义feign接口的模块都是没有启动类的模块,若想要在其他模块调用此模块中的feign接口,是否在Resource/META-INF/spring.factories中手动配置了feign接口的实现类

6、补充
feign接口写法示例:
 

import com.pig4cloud.pigx.admin.api.interceptor.FeignRequestInterceptor;
import com.pig4cloud.pigx.common.core.constant.ServiceNameConstants;
import com.xxl.job.core.biz.model.ReturnT;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import push.entity.MessagePush;

/**
 * @author
 * @date 2023/5/9
 * <p>
 * app消息推送服务
 */
@FeignClient(contextId = "remoteMessagePushService", value = ServiceNameConstants.PUSH_SERVER,configuration = {FeignRequestInterceptor.class})
public interface RemoteMessagePushService {

	/**
	 * app消息推送
	 * @param vo
	 * @return ReturnT
	 */
	@PostMapping("/lnrq/message/push")
	public ReturnT saveMessagePush(@RequestBody MessagePush vo);


}

import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.xxl.job.core.biz.model.ReturnT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import push.entity.MessagePush;
import push.service.impl.MessagePushServiceImpl;


/**
 * 业务类型表
 *
 * @author Roger 652321516@qq.com
 * @since 1.0.0 2023-04-03
 */
@RestController
@CrossOrigin
@RequestMapping("/lnrq/message")
public class MessagePushController {
	@Autowired
	private MessagePushServiceImpl messagePushServiceImpl;

	@Inner(value = false)
	@PostMapping("/push")
    public ReturnT push(@RequestBody MessagePush vo) {
		messagePushServiceImpl.saveMessagePush(vo);
        return new ReturnT("推送成功");
    }


}


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxl.job.core.biz.model.ReturnT;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import push.entity.MessagePush;
import push.handler.AliPush;
import push.handler.MessageSendDTO;
import push.mapper.MessagePushMapper;
import push.service.MessagePushService;

import java.util.concurrent.TimeUnit;


@Slf4j
@Service
@AllArgsConstructor
public class MessagePushServiceImpl extends ServiceImpl<MessagePushMapper, MessagePush> implements MessagePushService {

	@Autowired
	private   MessagePushMapper messagePushMapper;

	@Autowired
	private   RedisTemplate redisTemplate;

	@Autowired
	private AliPush aliPush;

	/**
	 * app推送消息,保存消息
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
	public ReturnT saveMessagePush(MessagePush vo) {
		//调用推送sdk
		MessageSendDTO dto =  new MessageSendDTO();
		dto.setTitle(vo.getTitle());
		dto.setContent(vo.getContent());
		aliPush.pushIOSMessage(dto,Long.valueOf(vo.getReceiveUserId()));
		aliPush.pushAndroidMessage(dto,Long.valueOf(vo.getReceiveUserId()));
		//入库
		 messagePushMapper.saveMessagePush(vo);
         Long id = vo.getId();
		//保存消息到 redis
		redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(MessagePush.class));
		redisTemplate.opsForHash().put("pm: push_massage", String.valueOf(id), vo);
		redisTemplate.expire("pm: push_massage", 90, TimeUnit.DAYS);
	    return ReturnT.SUCCESS;
	}

	/**
	 * 查询消息
	 */
	@Override
	public IPage<MessageSendDTO> getMessagePushList(Page page, MessageSendDTO params) {
		IPage<MessageSendDTO> result = messagePushMapper.getMessagePushList(page, params);
		return result;
	}



}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/520516.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

JetCache 使用简单案例到源码解析读这一篇就够

背景 github.com/alibaba/jet… 一、使用方法&#xff1a; 1. 创建项目— 此处使用springboot项目 2. 引入starter <dependency> <groupId>com.alicp.jetcache</groupId> <artifactId>jetcache-starter-redis</artifactId><version>2…

Servlet3.0 新特性全解

Servlet3.0新特性全解 tomcat 7以上的版本都支持Servlet 3.0 Servlet 3.0 新增特性 注解支持&#xff1b;Servlet、Filter、Listener无需在web.xml中进行配置&#xff0c;可以通过对应注解进行配置&#xff1b;支持Web模块&#xff1b;Servlet异步处理&#xff1b;文件上传AP…

DEV SIT UAT PET SIM PRD PROD常见环境英文缩写含义

一、英文缩写 英文中文 DEV development开发 SIT System Integrate Test系统整合测试&#xff08;内测&#xff09; UAT User Acceptance Test用户验收测试 PET Performance Evaluation Test性能评估测试&#xff08;压测&#xff09; SIM simulation仿真 PRD/PROD produ…

我们花一个月调研了小红书种草的新机会和增长策略

分析师&#xff1a;Jane、彬超 编辑&#xff1a;yolo 出品&#xff1a;增长黑盒研究组 *本报告为增长黑盒独立研究系列&#xff0c; 与第三方不存在任何利益关系 随着618的临近&#xff0c;小红书再次成为了品牌重要的“营销战场”。面临着经济环境的不确定性&#xff0c;想必各…

数据结构_串

目录 1. 串的定义和实现 1.1 串的定义 1.2 串的存储结构 1.2.1 定长顺序存储表示 1.2.2 堆分配存储表示 1.2.3 块链存储表示 1.3 串的基本操作 2. 串的模式匹配 2.1 简单的模式匹配算法 2.2 串的模式匹配算法——KMP算法 2.2.1 字符串的前缀、后缀和部分匹配值 2.2…

你不知道的裁员攻略:真正的离职赔偿是2N起步,不是N+1!计算赔偿金时,年终奖要计入总收入!...

最近裁员现象猖獗&#xff0c;许多人都不知道如何维护自己的合法权益&#xff0c;在和公司撕扯时屡屡被坑。一位曾经和字节撕过且成功的网友&#xff0c;友情给大家写了一份离职攻略。但要注意&#xff0c;这份攻略只针对那些守规矩的大公司&#xff0c;如果是不守规矩的小公司…

得ChatGPT者,得智能客服天下?

‍数据智能产业创新服务媒体 ——聚焦数智 改变商业 在现代社会&#xff0c;高效、专业的客服服务已成为企业、组织机构竞争力的关键要素。智能客服系统应运而生&#xff0c;智能客服系统对客服的赋能作用和价值主要表现在提高效率、降低成本、优化用户体验、深度挖掘用户需求…

【综述】结构化剪枝

目录 摘要 分类 1、依赖权重 2、基于激活函数 3、正则化 3.1 BN参数正则化 3.2 额外参数正则化 3.3 滤波器正则化 4、优化工具 5、动态剪枝 6、神经架构搜索 性能比较 摘要 深度卷积神经网络&#xff08;CNNs&#xff09;的显著性能通常归因于其更深层次和更广泛的架…

QML转换(Transformation)

目录 一 QML介绍 二 QML的使用场合 三 实例演示 一 QML介绍 QML是Qt Quick的缩写&#xff0c;它是一种新型的、面向对象的、跨平台的脚本语言&#xff0c;可以用来描述用户界面或应用程序的交互逻辑。QML可以在Qt应用程序中使用&#xff0c;也可以在其他JavaScript应用程序中…

Python入门(九)字典(二)

字典&#xff08;二&#xff09; 1.遍历字典1.1 遍历所有键值对1.2 遍历字典中的所有键1.3 按特定顺序遍历字典中的所有键 2.嵌套2.1 字典列表2.2 在字典中存储列表2.3 在字典中存储字典 作者&#xff1a;xiou 1.遍历字典 一个Python字典可能只包含几个键值对&#xff0c;也可…

【源码解析】SpringBoot自定义条件及@Conditional源码解析

自定义注解 自定义条件类 public class MessageCondition extends SpringBootCondition {Overridepublic ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {MultiValueMap<String, Object> attrs metadata.getAllAnnota…

成年人的崩溃只在一瞬间,程序员凌晨三点写的代码竟被女友删了...

对于恋爱中的情侣来说&#xff0c;吵架是很正常的事情&#xff0c;就算是再怎么亲密&#xff0c;也难免会出现意见不合的时候。 吵架不可怕&#xff0c;可怕的是&#xff0c;受吵架情绪的影响&#xff0c;做出一些比较“极端”的事情。 之前某社交平台上一位女生吐槽自己的男…

Ubuntu 本地部署 Stable Diffusion web UI

Ubuntu 本地部署 Stable Diffusion web UI 0. 什么是 Stable Diffusion1. 什么是 Stable Diffusion web UI2. Github 地址3. 安装 Miniconda34. 创建虚拟环境5. 安装 Stable Diffusion web UI6. 启动 Stable Diffusion web UI7. 访问 Stable Diffusion web UI8. 其他 0. 什么是…

我这里取出来的数据(最后边的excel)有点问题,我没有要取性别的数据,但是表里有...

点击上方“Python爬虫与数据挖掘”&#xff0c;进行关注 回复“书籍”即可获赠Python从入门到进阶共10本电子书 今 日 鸡 汤 上穷碧落下黄泉&#xff0c;两处茫茫皆不见。 大家好&#xff0c;我是皮皮。 一、前言 前几天在Python钻石群【不争】问了一个Python自动化办公的问题&…

PyCharm安装教程,图文教程(超详细)

「作者简介」&#xff1a;CSDN top100、阿里云博客专家、华为云享专家、网络安全领域优质创作者 「推荐专栏」&#xff1a;对网络安全感兴趣的小伙伴可以关注专栏《网络安全入门到精通》 PyCharm 一、PyCharm下载安装二、Python下载安装三、创建项目四、安装模块1、pip安装2、P…

商城系统商品属性的数据库设计思路

京东商城的数据库是如何搭建的&#xff0c;那么多商品&#xff0c;每种商品的参数各不相同&#xff0c;是怎样设计数据库的&#xff1f; 在提及这种设计思路前&#xff0c;首先得了解数据表可以分为两种结构: 1\横表,也就是我们经常用到的表结构&#xff0c; 2\纵表,这种结构…

ASEMI代理LT8609AJDDM#WTRPBF原装ADI车规级芯片

编辑&#xff1a;ll ASEMI代理LT8609AJDDM#WTRPBF原装ADI车规级芯片 型号&#xff1a;LT8609AJDDM#WTRPBF 品牌&#xff1a;ADI /亚德诺 封装&#xff1a;DFN-10 批号&#xff1a;2023 安装类型&#xff1a;表面贴装型 引脚数量&#xff1a;10 工作温度:-40C~125C 类型…

MySQL学习---13、存储过程与存储函数

1、存储过程概述 MySQL从5.0版本开始支持存储过程和函数。存储过程和函数能够将负杂的SQL逻辑封装在一起&#xff0c;应用程序无序关注存储过程和函数内部复杂的SQL逻辑&#xff0c;而只需要简单的调用存储过程和函数就可以。 1.1 理解 含义&#xff1a;存储过程的英文是Sto…

ASEMI代理LTC2954CTS8-2#TRMPBF原装ADI车规级芯片

编辑&#xff1a;ll ASEMI代理LTC2954CTS8-2#TRMPBF原装ADI车规级芯片 型号&#xff1a;LTC2954CTS8-2#TRMPBF 品牌&#xff1a;ADI/亚德诺 封装&#xff1a;TSOT-23-8 批号&#xff1a;2023 引脚数量&#xff1a;23 工作温度&#xff1a;-40C~85C 安装类型&#xff1a…

若依框架(RuoYI)项目打包(jar)方法,部署到 Linux 服务器

序言 在若依框架的 bin 目录下&#xff0c;存在着三个 bat 文件&#xff0c;一个是清除之前的依赖的自动化 bat 脚本&#xff08;clean.bat&#xff09;&#xff0c;一个是自动化项目打包的 bat 脚本&#xff08;package.bat&#xff09;&#xff0c;一个是运行若依项目的脚本…