一、背景

笔者项目中。有两个子模块代码。需要分别在不同的包名中运行,假设一个包名为 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 错误的解决办法的更多相关文章

  1. 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. 添 ...

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

  3. 【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的情 ...

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

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

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

  6. 记一个SpringBoot中属性注入失败的问题Consider defining a bean of type ''' in your configuration

    今天遇到的一个问题: 代码检查了好几次,都没有错误,但是启动时就会报错Consider defining a bean of type ''' in your configuration. 启动类在c ...

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

  8. Spring Boot:Consider defining a bean of type '*.*.*' in your configuration解决方案

    果然不看教程直接使用在遇到问题会懵逼,连解决问题都得搜半天还不一定能帮你解决了... ***************************APPLICATION FAILED TO START*** ...

  9. Consider defining a bean of type 'XX.XX.XX.XX.mapper.XXMapper' in your configuration.

    今天构建一个springboot 项目,采用mybatis+mysql 然后就出现了这种错误....浪费我半天时间 Description: Field loginLogMapper in com.g ...

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

随机推荐

  1. Vue 实现点击空白处隐藏某节点

    手动监听判断 <template> <div> <span ref="projectButton"> <el-popover v-mode ...

  2. 【Java】取n工作日后的日期(仅排除周六周日)

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.*; import java. ...

  3. node 内存全局配置(--max-old-space-size)

    安装完了node和angular之后,使用powershell 窗口进行 ng build --prod打包,会提示内存溢出:JavaScript heap out of memory. 项目内打包解 ...

  4. C# 读取串口设备列表

    ManagementObjectSearcher 解析不到头文件,需要手动 Add Referance 需要添加引用:System.Management,然后引入命名空间:using System.M ...

  5. GO 语言中的 sync Map

    为什么需要 sync map go 语言之所以引入 sync.Map主要是因为GO 语言自带的 map 是线程不安全的.只能保证并发的读,但是不能保证并发的写. 看下面的例子: func main() ...

  6. oracle ebs 账户组合验证

    DECLARE l_segment1 GL_CODE_COMBINATIONS.SEGMENT1%TYPE; l_segment2 GL_CODE_COMBINATIONS.SEGMENT2%TYPE ...

  7. python翻译(一)

    有道翻译 # -*- coding: UTF-8 -*- import requests import time import random import hashlib #用于md5加密 ''' 有 ...

  8. [JavaScript]关于prototype继承

    When it comes to inheritance, JavaScript only has one construct: objects. Each object has a private ...

  9. sublime4 支持中文

    sublime_text_build_4143_x64_setup 安装完毕后,工具,命令面板,install package,ChineseLocalizations

  10. Linux的stat命令结果说明

    There are 3 kind of "timestamps": Access - the last time the file was read Modify - the la ...