记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 ...
随机推荐
- 微信带参数的小程序码生成并上传到七牛云(java)
在大家看正式内容之前请耐心的听我把这段话说完:我冒昧的猜一下,你为了解决问题估计已经看了很多文章了,如果这边文章能给你带来帮助,不胜荣幸,如果有错误也请批评指正,共同进步,我之前在完成这个功能之前,从 ...
- 查看当前linux进程所在的目录
1.通过 ps -ef | grep xxx 查看进程信息 ps -ef | grep rsi 1 2.通过 ll /proc/PID 命令查看进程所在目录位置 ls -l /proc/PID 1 L ...
- org.aspectj.lang不存在,引入失败。
问题:添加了依赖,或引入了jar包但是写aspect类时无法引入 解决办法:
- ESXI虚拟机 硬盘扩容/目录(添加新硬盘)
背景: 线上服务器,磁盘Linux的虚拟机根分区已经使用90%,触发了磁盘告警,再一顿操作删除后,勉勉强强回到了82%,现在需要对根目录进行扩容. 进入到EXSI管理平台,看到原来的sda磁盘只有30 ...
- 如何实现基于GPIO按键的长按,短按,双击
不同的架构实现并不相同,所以我分成了两中:STM32平台和其他平台: STM32平台 首先要分析:该如何判断当前的按键状态:单机和双击是通过在有限时间内是否有新的按动作产生 -- 所以需要一个记录按键 ...
- Python异步爬取梁羽生小说网
才知道写在文章里面不是原创... https://www.cnblogs.com/kebei/articles/14659937.html
- UCOS-III笔记
1.单片机程序分类:轮询程序,前后台程序,多任务系统程序 2.多任务系统伪代码 1 int flag1 = 0; 2 int flag2 = 0; 3 int flag3 = 0; 4 5 int m ...
- create_base_x.txt
create table g_temp.test_base( field_date date, field_str varchar(100) , field_int integer ) drop ta ...
- 模型admin 外键的相关操作
....@admin.register(MyModel)class MyModelAdmin(admin.ModelAdmin): def method(self, request, queryset ...
- linux运维之道学习笔记
linux常用命令 1.find命令 find / "*.log" 查找/目录下.log结尾的档案 find / -mtime -3 查找/目录下三天内被修改的档案 find / ...