记SpringBoot中 Consider defining a bean of type 'com.xxx.classname' in your configuration 错误的解决办法
一、背景
笔者项目中。有两个子模块代码。需要分别在不同的包名中运行,假设一个包名为 cn.com.a,另一个包名为cn.com.b。由于启动类只加了@SpringBootApplication注解,所以Springboot默认是在主类所在的包名下扫描,并注册bean,而现在项目已被分解为不同的模块,各自包名不同,因此报错 Consider defining a bean of type 'com.xxx.classname' in your configuration。
二、原因描述
项目已被分解为不同的模块,因此需要在主类上。指定独立模块要扫描的类或包。
三、解决方案
如下代码所示,先加上@ComponentScan 注解,如果报错 JpaRepositories 和 Entity 错误,再加上第2和第3行。
1 @ComponentScan(basePackages = {"cn.com.a", "cn.com.b"})
2 @EnableJpaRepositories(basePackages = {"cn.com.a", "cn.com.b"})
3 @EntityScan(basePackages = {"cn.com.a", "cn.com.b.domain"})
4 public class CcnGuardApplication implements CommandLineRunner {
}
记SpringBoot中 Consider defining a bean of type 'com.xxx.classname' in your configuration 错误的解决办法的更多相关文章
- Consider defining a bean of type 'com.*.*.mapper.*.*Mapper' in your configuration.
@Mapper 不能加载的问题 Consider defining a bean of type 'com.*.*.mapper.*.*Mapper' in your configuration. 添 ...
- Consider defining a bean of type 'com.*.*.feign.*FeignClient' in your configuration.
Description: Field *FeignClient in com.*.*.service.* required a bean of type '***********' that coul ...
- 【Git初探】Git中fatal: Not a git repository (or any of the parent directories): .git错误的解决办法
今天用git bash更新项目时遇到了无论使用什么命令都会报fatal: Not a git repository (or any of the parent directories): .git的情 ...
- springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.
一.前言: 使用springboot自动注入的方式搭建好了工程,结果启动的时候报错了!!!,错误如下图: Description: Field userEntityMapper in com.xxx. ...
- maven多模块启动required a bean of type com.xxx.xxx.service that could not be found.
Description: Field testService in com.xxx.xxx.api.controller.TestController required a bean of type ...
- 记一个SpringBoot中属性注入失败的问题Consider defining a bean of type ''' in your configuration
今天遇到的一个问题: 代码检查了好几次,都没有错误,但是启动时就会报错Consider defining a bean of type ''' in your configuration. 启动类在c ...
- Consider defining a bean of type 'package' in your configuration [Spring-Boot]
https://stackoverflow.com/questions/40384056/consider-defining-a-bean-of-type-package-in-your-config ...
- Spring Boot:Consider defining a bean of type '*.*.*' in your configuration解决方案
果然不看教程直接使用在遇到问题会懵逼,连解决问题都得搜半天还不一定能帮你解决了... ***************************APPLICATION FAILED TO START*** ...
- Consider defining a bean of type 'XX.XX.XX.XX.mapper.XXMapper' in your configuration.
今天构建一个springboot 项目,采用mybatis+mysql 然后就出现了这种错误....浪费我半天时间 Description: Field loginLogMapper in com.g ...
- Consider defining a bean of type 'com.lvjing.dao.DeviceStatusMapper' in your configuration.
"C:\Program Files\Java\jdk1.8.0_181\bin\java.exe" "-javaagent:C:\Program Files\JetBra ...
随机推荐
- ansible自动化管理
一图读懂ansible自动化运维 金山文档连接地址:https://www.kdocs.cn/view/l/cheHWG9tTEgN(可查看) __outline__ansible部署及说明参数说明& ...
- centos系统时间与硬件时间不一致
centos系统时间与硬件时间设置.同步 将系统时间设置成2018年7月31日 12:00:00 date -s "07/31/18 12:00:00" hwclock -s 将 ...
- CentOS系统上离线部署MySQL
卸载自带Mariadb 1.[卸载前确认系统是首次安装使用,以防止误删用户数据],初次安装默认系统会自带Mariadb,卸载moriadb. 操作方式: 查找:# rpm -qa|grep maria ...
- Python 切片/列表/字符串之间装换
1. 怎么实现字符串变为list 使用split(),把字符串拆分再存入数组: 例子 input="ni si shi" output=input.split(" &qu ...
- starlette.routing.NoMatchFound
目前正在学习FastAPI, 目前是学习到了引入静态文件.这是我引入的本地文件的方式 url_for('/static', path='/imgs/favicon.ico') 只要启动服务,就会报错5 ...
- 高效XML绑定框架JIBX
高效XML绑定框架JIBX demo源码地址 https://gitee.com/clover-clover/clover.git 具体路径: clover/clover-frame/clover-f ...
- 【B站】B站计算集数时长,调节任意倍速
打开浏览器,任意收藏一个网址,将URL替换为下面的代码并保存 打开任意B站视频页面,点击这个收藏的网址,即可在页面右边看到如下窗口 javascript: (function () { var hou ...
- loadrunner---脚本录制常见问题
一:loadrunner录制脚本时ie浏览器不弹出? 1.IE浏览器取消勾选[启用第三方浏览器扩展]启动IE,从[工具]进入[Internet选项],切到高级,去掉[启用第三方浏览器扩展(需要重启动) ...
- 学习-自增id++的问题
代码示例: let id = 0 const todos = ref([ { id: id++, text: 'Learn HTML' }, { id: id++, text: 'Lear ...
- PID模板
typedef struct{ float Kp,Ki,Kd; float Target; float Current; float Error[3]; float DeadZone; float O ...