背景:在同一个项目中分模块创建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