大家好,我是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 问题解决方案相关推荐

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

    搭建完spring boot的demo后自然要实现自动注入来体现spring ioc的便利了,但是我在实施过程中出现了这么一个问题,见下面,这里找到解决办法记录下来,供遇到同样的问题的同僚参考 Des ...

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

    1.可能该实现类上没有@Service或@Component 2.可能是idea的启动配置未配置当前项目路径

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

    一.前言: 使用springboot自动注入的方式搭建好了工程,结果启动的时候报错了!!!,错误如下图: Description:Field userEntityMapper in com.xxx.x ...

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

    Consider defining a bean of type 'XXX' in your configuration 出现这个错误,要看看你是否用到了某些组件,但是启动类上没加相应的注解.比如说我 ...

  5. 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 ...

  6. 【无法找到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 ...

  7. 解决启动报错Consider defining a bean of type ‘xxx‘ in your configuration.

    解决启动报错Consider defining a bean of type 'xxx' in your configuration. 报错截图 解决方法:查看注解是否同时存在@AllArgsCons ...

  8. [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 ...

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

    当你的spring web项目运行时突然报Consider defining a bean of type 'xxx' in yourconfiguration这个样的异常时,不妨试试以下骚操作解决问 ...

最新文章

  1. ERP项目选型实施注意的几点(二)
  2. mybaits六:参数处理
  3. 用python函数画德国国旗代码_python海龟绘图之画国旗实例代码
  4. ubuntu openstack spice
  5. LogBack 入门实践
  6. (王道408考研数据结构)第八章排序-第一节:排序综述
  7. Dlib 19.14发布——增加了一个训练RBF-SVM的auto-ML工具
  8. 北京人工智能工程师职称评定政策出台,明年起一年一评
  9. CYYMysql 源码解读 4
  10. axios的介绍与页面配置---axios工作笔记003
  11. 第三方支付接口游戏商户池轮巡、支付宝商户池、微信商户池、游戏商户池怎么申请?
  12. 【python】习题 1-4周
  13. cors js解决js跨域问题
  14. oracle 日志查看教程,Oracle 查看日志
  15. JS怎么唤起百度地图
  16. 一个系统同时装office2007和2019时遇到的问题及解决方案
  17. 我的世界java版mac切视角_我的世界伤害视角倾斜
  18. myeclipse10 用破解补丁或注册机不能成功破解原因解析
  19. 利用EXCEL函数LINEST进行统计学中的回归分析
  20. PTA Sheldon的小本本

热门文章

  1. Docker快速搭建OpenProject项目管理协作平台
  2. 公众号裂变涨粉技巧,快速实现拉新~
  3. 为什么说 WASM 是 Web 的未来?
  4. 杜克大学计算机数据科学,杜克大学的数据科学专业解析
  5. pandas日期 识别周
  6. Abp.Zero 手机号免密登录验证与号码绑定功能的实现(一):验证码模块
  7. 从零学本体dApp开发(26):本体签名服务的API与Postman
  8. 跟着狂神聊聊现在和未来
  9. 一文搞懂SQL中的各种联结——内联结、自然联结、自联结、交叉联结
  10. 利用逆透视变换获取车载图象的鸟瞰图