SpringBoot 出现 Consider defining a bean of type ‘xxx‘ in your configuration 问题解决方案
大家好,我是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 ‘xxx‘ in your configuration 问题解决方案相关推荐
- 关于spring boot自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration问题解决方案
搭建完spring boot的demo后自然要实现自动注入来体现spring ioc的便利了,但是我在实施过程中出现了这么一个问题,见下面,这里找到解决办法记录下来,供遇到同样的问题的同僚参考 Des ...
- 关于spring boot应用自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration问题解决方案
1.可能该实现类上没有@Service或@Component 2.可能是idea的启动配置未配置当前项目路径
- springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.
一.前言: 使用springboot自动注入的方式搭建好了工程,结果启动的时候报错了!!!,错误如下图: Description:Field userEntityMapper in com.xxx.x ...
- springboot启动报错: Consider defining a bean of type ‘XXX‘ in your configuration
Consider defining a bean of type 'XXX' in your configuration 出现这个错误,要看看你是否用到了某些组件,但是启动类上没加相应的注解.比如说我 ...
- Consider defining a bean of type `xxx` in your configuration问题解决
Consider defining a bean of type `xxx` in your configuration问题解决 参考文章: (1)Consider defining a bean o ...
- 【无法找到FeignClient的bean】 Consider defining a bean of type ‘xxx‘ in your configuration.
Consider defining a bean of type 'xxx' in your configuration. 错误原因:该FeignClient接口在其他jar包中,@EnableFei ...
- 解决启动报错Consider defining a bean of type ‘xxx‘ in your configuration.
解决启动报错Consider defining a bean of type 'xxx' in your configuration. 报错截图 解决方法:查看注解是否同时存在@AllArgsCons ...
- [SpringBoot报错]Consider defining a bean of type ‘xxx‘ in your configuration, NoSuchBeanDefinitionExce
报错详情: Error starting ApplicationContext. To display the conditions report re-run your application wi ...
- Consider defining a bean of type ‘xxx‘ in your configuration
当你的spring web项目运行时突然报Consider defining a bean of type 'xxx' in yourconfiguration这个样的异常时,不妨试试以下骚操作解决问 ...
最新文章
- ERP项目选型实施注意的几点(二)
- mybaits六:参数处理
- 用python函数画德国国旗代码_python海龟绘图之画国旗实例代码
- ubuntu openstack spice
- LogBack 入门实践
- (王道408考研数据结构)第八章排序-第一节:排序综述
- Dlib 19.14发布——增加了一个训练RBF-SVM的auto-ML工具
- 北京人工智能工程师职称评定政策出台,明年起一年一评
- CYYMysql 源码解读 4
- axios的介绍与页面配置---axios工作笔记003
- 第三方支付接口游戏商户池轮巡、支付宝商户池、微信商户池、游戏商户池怎么申请?
- 【python】习题 1-4周
- cors js解决js跨域问题
- oracle 日志查看教程,Oracle 查看日志
- JS怎么唤起百度地图
- 一个系统同时装office2007和2019时遇到的问题及解决方案
- 我的世界java版mac切视角_我的世界伤害视角倾斜
- myeclipse10 用破解补丁或注册机不能成功破解原因解析
- 利用EXCEL函数LINEST进行统计学中的回归分析
- PTA Sheldon的小本本