springboot 扫描外部controller文件

背景:在同一个项目中分模块创建controller文件夹,在打包的时候只打包相对应的controller,而不是打包所有;除controller外其他文件都是共用的。
一、项目目录结构
在这里插入图片描述
从目录结构可以看到,当启动类 ManagerApplication 启动后是扫描不到 controller 类的,所以在启动类中需要配置
在这里插入图片描述
这样就能扫描到外部的 controller 文件了。
二、在打包的时候打包指定的文件
pom.xml配置

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-war-plugin</artifactId>
     <configuration>
          <!--排除掉war包指定文件(*:文件夹下所有文件;**:文件夹下所有文件,包含子文件夹的文件)-->
          <packagingExcludes>WEB-INF/classes/com/文件路径/controller/business/*</packagingExcludes>
     </configuration>
</plugin>

在这里插入图片描述

记录一个微服务项目报错 springboot 启动保存

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'categoryInfoController': 
Injection of resource dependencies failed; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'categoryInfoService': 
Unsatisfied dependency expressed through field 'baseMapper'; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type 'com.ys.medical.base.mapper.CategoryInfoMapper' available: 
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: 
{@org.springframework.beans.factory.annotation.Autowired(required=true)}

解决方法
1、SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描!
2、“Application类”是指SpringBoot项目入口类。这个类的位置很关键
3、如果Application类所在的包为:com.demo.module,则只会扫描com.demo.module包及其所有子包,如果service或dao所在包不在com.demo.module及其子包下,则不会被扫描!
4、所以需在application启动类中加上
@MapperScan(“com.*.dao”)//加上你项目的dao或service所在文件位置即可
@SpringBootApplication

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值