SpringBoot 出现 Consider defining a bean of type ‘xxx‘ in your configuration 问题解决方案

SpringBoot自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration问题解决方案 错误描述 *************************** APPLICATION FAILED TO START *************************** Description: Field redisUtil in org.manager.common.springsecurity.filter.JwtAuthorizationTokenFilter required a bean of type 'org.common.tool.redis.RedisUtil' that 阅读详情
AI摘要

在Spring Boot项目开发中,遇到'Consider defining a bean of type 'xxx' in your configuration'的问题通常是由于Spring容器未扫描到其他模块中的bean导致的。该问题出现在模块B尝试@Autowired注入模块A的bean时,因为模块B的Spring容器没有注册模块A的bean。解决方法是在模块B的主配置类中增加scanBasePackages属性,指定需要扫描的包,包括模块A的包,确保所有需要的bean都被正确注册。例如,可以将scanBasePackages设置为{'com.trikey.common','com.trikey.jwt'}

大家好,我是trikey。

最近在编写练手项目代码时,出现了Consider defining a bean of type 'xxx' in your configuration 问题,这里简单记录一下解决的方案。

一、问题场景

模块A:存放公共类和方法的模块,对应包名为:com.trikey.common。

模块B:业务模块,对应包名为:com.trikey.jwt ,在pom.xml中已经导入模块A。

问题:

当我在模块B的某个接口中使用@Autowired注入了模块A中定义的bean,启动项目时,出现 Consider defining a bean of type 'xxx' in your configuration 问题。

二、问题原因

每一个Spring项目都有独立的Spring容器去存储自己项目中所注册的bean,模块B中的Spring容器加载时未能将模块A中所定义的bean注册进Spring容器中,导致开发时@Autowired注入模块A中的bean进行使用时,找不到对应的bean,才会出现 Consider defining a bean of type 'xxx' in your configuration 问题。

三、解决办法

让模块B的Spring容器启动时,去扫描模块A包下的所有的组件并注册到模块B的Spring容器中,这样问题就解决了。

如下图所示:

package com.trikey.jwt;

import com.trikey.common.util.SpringContextUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication(scanBasePackages = {"com.trikey.common","com.trikey.jwt"})
@MapperScan("${mybatis-plus.mapperPackage}")
public class TrikeySsoJwtApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext applicationContext = SpringApplication.run(TrikeySsoJwtApplication.class, args);
        SpringContextUtil.setApplicationContext(applicationContext);
    }

}

SpringBoot 出现 Consider defining a bean of type ‘common.utils.SFTPUtil‘ in your configuration 问题解决方案 在模块B的某个接口中使用@Autowired注入了模块A中定义的bean 阅读详情

相关推荐

图学习——04.HAN(异构图注意力网络)

什么是异构图,什么是元路径,什么是HAN,怎么计算attention,节点级别的attention和语义级别的attention

m0_51474171的博客 3010

关于报错Consider defining a bean of type 的解决

关于报错Consider defining a bean of type 的解决 引用: https://blog.csdn.net/qq_41937388/article/details/106967610

automal的博客 23万+

《Ventoy 制作系统安装 U 盘的具体步骤》

然后您可以在电脑的磁盘管理中对 U 盘进行快速格式化,选择 FAT32 或 NTFS 文件系统。至此,Ventoy 系统安装 U 盘就制作完成了。您可以在需要安装系统的电脑上,从 U 盘启动,然后选择相应的系统镜像进行安装。安装完成后,将您需要的操作系统镜像文件(如 Windows、Linux 等的 ISO 格式镜像)复制到 U 盘的根目录。在安装程序中,选择您插入的 U 盘设备,确保选择正确,以免误操作。2. 确认选择的 U 盘盘符正确,防止误操作导致其他磁盘数据丢失。点击“安装”按钮,等待安装完成。

jiyiwangluokeji的博客 2693

Consider defining a bean of type ‘XXX’ in your configuration.

SpringBoot启动报错Consider defining a bean of type ‘XXX’ in your configuration. 在业务模块集成公共模块的时候,将业务模块的domain层、mapper层、service层移动到公共模块,提高代码的复用性,易于维护和扩展。 改造好了之后,启动时却报错了。如上图。 大意是咱业务模块的controller中没有咱service层的这个bean。 自己解决的时候是先去查看包名有没有写错,位置有没有对。发现没有问题之后查看service的实现类.

sc2_unlimited的博客 1万+

保姆级教程:用Docker Compose一键部署WVP-PRO+ZLM+录像服务(含Nginx反代)

本文提供了一套完整的容器化GB28181视频平台部署方案,通过Docker Compose实现WVP-PRO、ZLMediaKit(ZLM)和录像服务的一键式部署。详细介绍了环境准备、架构设计、容器化部署实战以及高级配置优化,帮助用户快速搭建高性能视频监控管理平台,适用于安防行业和物联网设备管理场景。

weixin_30415113的博客 868

基于STM32单片机设计的红外人脸测温仪(QT上位机)

基于STM32单片机设计的红外人脸测温仪(QT上位机)是一种结合红外测温和人脸识别技术的设备,可以快速、非接触地测量人体体温并识别身份,广泛应用于人员密集场所的体温筛查和出入管理。基于STM32单片机设计的红外人脸测温仪是一种功能实用、易于使用的人脸测温设备,可以有效提高测温效率和识别准确率,广泛应用于各类人员密集场所的体温筛查和出入管理。

走向CTO的路上... 1723

Spring Boot Consider defining a bean of type `xxx` in your configuration 错误6种情况解决(Spring、Dubbo、JPA等)

2、UserService启动装配时变量名默认为实现类的名字userServiceImpl,实现类是UserServiceImpl类,而我们使用@Autowired注解时变量名为userService。(1)将当前模块的Dao类、Service类、Entity类、Controller类放在和XxxApplication启动类同一目录下或者子目录下。3、由于要自定义Dao类,这个自定义Dao类跟其他Dao类在类的定义上会不一样,如果自定义Dao类跟其他Dao类在类的定义上一样,会导致报错。

weixin_44917365的博客 3万+

【部署】Ubuntu 24.04.4虚拟机下部署OpenClaw

OpenClaw是一款基于AI的智能助手工具,本文详细介绍了在Ubuntu 24.04.4系统上的三种安装方法。推荐使用一键安装脚本(curl -fsSL https://openclaw.ai/install.sh | bash),自动完成Node.js检测、CLI安装和引导配置。对于开发者,提供了从源码构建的详细步骤,包括环境准备、依赖安装和构建流程。文章还包含常见问题解决方案(如sharp构建错误处理)以及后续维护建议(更新、配置检查和日志查看)。安装完成后,用户可通过终端TUI或Web UI进行初始

海兰 1万+

关于spring boot自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration问题解决方案

搭建完spring boot的demo后自然要实现自动注入来体现spring ioc的便利了,但是我在实施过程中出现了这么一个问题,见下面,这里找到解决办法记录下来,供遇到同样的问题的同僚参考   Description: Field helloService in com.example.demo.service.TestController required a bean of type '...

一味前行 6万+

DDR5 的 PI: DIMM 上 PMIC,正在制造一批“新型 EMI 问题”

DDR5 的 PI,不再只是“供电设计”,而是一次“噪声管理设计”。电压稳定本地调节高频噪声EMI 风险系统不确定性DDR5 真正难的地方,不是跑起来,而是——在最差条件下,它还能不能一直跑。而 DIMM 上那颗 PMIC,正是你绕不开的关键角色。

weixin_43199439的博客 196

Windows 上 openclaw onboard --install-daemon 命令的安装位置和启动配置

摘要:Windows系统中,执行openclaw-cnonboard--install-daemon命令会创建计划任务OpenClawGateway,该任务在用户登录时自动运行位于%USERPROFILE%.openclaw\gateway.cmd的脚本文件来启动服务。管理方法包括通过任务计划程序或命令行(schtasks)查看/启停任务,使用openclaw gateway命令操作服务,或通过删除计划任务和脚本文件完全卸载服务。该机制确保OpenClawGateway服务随系统登录自动启动。(149字)

大坡3D软件开发 1393

关于Spring Boot自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration问题解决方案

在Spting Boot项目中自然要使用实现自动注入来体现Spring IOC的便利了, 但是我在实施过程中出现了这么一个问题, 如下, 这里找到解决办法记录下来,供遇到同样的问题的同僚参考 2021-04-08 23:07:04.596 ERROR 18156 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START

qq_28342873的博客 1232

自动化上位机开发C#100例:如何用面向对象的方式封装雷赛运动控制卡EtherCAT总线卡(C#代码)

自动化上位机开发C#100例:雷赛运动控制卡EtherCAT总线卡C#封装类。

十多年IT经验,专注机器视觉,智能制造半导体行业 5051

SpringBoot报错Consider defining a bean of type ‘xxx’ in your configuration

SpringBoot报Consider defining a bean of type ‘xxx’ in your configuration怎么解决 首先看下代码:问题是自动注入User类的user对象失败,意思就是没有找到这个类,即这个类没有注入到Spring容器中。 (service实现类已经加了@service注解) @RestController public class UserController { @Autowired User user; @Autowired

Wow 五六 !!! 的博客 1627

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.

一.启动项目时报错信息如下 Description: Field userEntityMapper in com.xxx.xxx.service.UserService required a bean of type ‘com.xxx.xxx.dao.UserEntityMapper’ that could not be found. Action: Consider defining a bea...

匆匆321 1万+

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Consider defining a bean of type ‘xxx.xxxMapper‘ in your configuration

集成MyBatis,报如下错误: Description: Field userMapper in com.example.demo.service.impl.UserServiceImpl required a bean of type 'com.example.demo.dao.IUserMapper' that could not be found. The injection point has the following annotations: - @org.springfr...

鲁迷那的专栏—坚持实践后再写出来! 1万+

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

SpringBoot启动报错“Consider defining a bean of type ‘xxx.mapper.UserMapper‘ in your configuration.“

异常 启动SpringBoot项目报错: 2021-06-25 15:32:39.540 WARN 23108 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDepe

二木成林 4万+

springboot+mybatis 启动报错 Consider defining a bean of type ‘xxx’ in your configuration.

springboot+mybatis 启动报错 Consider defining a bean of type ‘xxx’ in your configuration希望此解决方案可以解决你们的问题,没有解决也别气馁,继续加油!!! 第一次使用springboot来创建一个项目,并且还是多模块项目,因此在搭建过程中就遇到了如下问题: 具体错误信息内容: ********************...

Tinna_Tammy的博客 3346

【SpringBoot常见报错与解决方案】SpringBoot 启动报错:Consider defining a bean of type ‘xxx‘ in your configuration?

你想要的东西,Spring 容器里没有。想被注入,先成 Bean;想成 Bean,先加注解 + 在扫描路径内。下次再看到,别慌,打开 checklist,3 分钟搞定!

Mc、科 936

springboot启动报错: Consider defining a bean of type ‘XXX‘ in your configuration

Consider defining a bean of type ‘XXX’ in your configuratio 出现这个错误,要看看你是否用到了某些组件,但是启动类上没加相应的注解。比如说我就是因为在service层用到了@FeignClient注解,但是在启动类上忘了加上@EnableFeignClients注解,才导致的报错,写代码一定要细心啊。 异常信息如下: Description: A component required a bean of type 'com.atgugu.sp

weixin_45112201的博客 3161

关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案

关于spring boot自动注入出现Consider defining a bean of type ‘xxx’ in your configuration问题解决方案 使用springboot搭建项目的时候出现了springboot无法扫描到mapper文件的问题。 经过查找,发现出现这个情况都基本是mapping.xml文件中的namespace路径出现问题,或者是没有指定扫描mapper文...

Pickup_No的博客 4199

解决Consider defining a bean of type ‘XXX’ in your configuration.

解决Consider defining a bean of type ‘XXX’ in your configuration.

A515754的博客 6351

【springboot】自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration的问题

Consider defining a bean of type ‘com.example.ch2_1_1.repository.TodoRepository’ in your configuration. 我写的几个类 实体 接口 控制类 但运行时出错spring给建议为Consider defining a bean of type ‘xxx‘ in your configuration 英文提示为在配置中找不到一个指定自动注入类型的bean,在正常情况下@Component注解的类会自动被Spr

weixin_44274319的博客 1万+
上一篇: java:Thread和Runnable的区别
trikeys
博客等级 码龄7年 2粉丝 8原创
评论 7
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值