创建子module模块过程参考:点击跳转
注意创建子模块后需要在根目录下的pom.xml和启动模块下的pom.xml添加子模块依赖。
自定义包名后如何确保正确扫描?
springboot的包扫描默认配置为启动类所在的包,及子包,所以放在com.ruoyi包下的都可以被扫描到。
自定义包名后需要在启动类里新增@MapperScan和@ComponentScan来实现所有的包扫描。
/**
* 启动程序
*/
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class })
@MapperScan(value = {
"com.test.*.mapper","com.ruoyi.*.*.mapper"})
@ComponentScan(value = {
"com.test","com.ruoyi"} )
public class Application
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
System.out.println("启动成功");
}
}
新增的子模块实体需要在 application.yml 中 mybatis - typeAliasesPackage 增加 子模块的实体扫描
mybatis-plus:
# 对应的 XML 文件位置
mapper-locations: classpath*:mapper/**/*Mapper.xml
# 实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: com.ruoyi.**.domain,com.test.*.*.entity