记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 ...
随机推荐
- vue 使用mixin
mixin 混入 混入提供了一种非常灵活的方式,来分发Vue组件中可以复用的功能,一个混入对象可以包括任意的组件选项,当组件使用混入对象时,所有的混入对象的选项 将被'混合'进入该组件本身的选项,混入 ...
- Linux 服务器内存异常问题记录
一.内存异常 1. 问题描述:服务器内存一会儿就增加1G,但也没有看到有消耗内存较大的进程:最后联想到项目最近做ARM架构适配,有变更代码,立马想到使用的SSH组件,一查看就发现有大量的进程: 解决办 ...
- ZooKeeper的主要应用场景
什么是Zookeeper ZooKeeper主要服务于分布式系统,可以用ZooKeeper来做:统一配置管理.统一命名服务.分布式锁.集群管理. 使用分布式系统就无法避免对节点管理的问题(需要实时感知 ...
- 反射的学习笔记--sql语句生成
学生实体类 public class Student { public int Id { get; set; } public string Name { get; set; } public int ...
- SDN第二次实验
一.实验目的能够对Open vSwitch进行基本操作:能够通过命令行终端使用OVS命令操作Open vSwitch交换机,管理流表:能够通过Mininet的Python代码运行OVS命令,控制网络拓 ...
- android修改frameework与service,vendor分区需要替换的文件
1. 修改framework代码 需要将framework.jar包提供给android studio使用,并替换车机内文件(两种framework.jar不是同一文件,一个是生成文件一个是安卓目录文 ...
- npm查询所有可以安装的包
npm view 包名 versions
- linux下进程和线程的区别和联系
进程用fork()或者vfork()生成(vfork是专门为了加载其他程序的子程序而优化的,随着fork()的优化,vfork已经被优化) fork()生成的子进程与父进程共享代码区内存,对于其他内存 ...
- hadoop集群搭建之测试集群,配置历史服务器,日志聚集,时间同步
hadoop集群搭建之测试集群,配置历史服务器,日志聚集,时间同步前期概要:我们完全分布式集群已经搭建完毕,并且还写了群启/群关的脚本, 接下来有必要来测试一遍集群,我们可以使用官方的案例,用它们在集 ...
- eval()
s='12*2'd=eval(s)#字符串运算函数print(d) 结果: 24