spring boot 配置访问其他模块包中的mapper和xml

maven项目结构如下,这里只是简单测试demo,使用的springboot版本为2.1.3.RELEASE

1、comm模块主要是一些mybatis的mapper接口和对应的xml文件,以及数据库表实体映射类,目录结构

2、bat模块包含调用comm模块的mapper接口的service服务,以及测试controller,引入comm模块作为依赖,目录结构

涉及点:

@MapperScan配置mapper路径

@SpringBootApplication
// 路径设置为comm模块的mapper路径
@MapperScan(basePackages = {"com.kinson.comm.mapper"})
public class BatApplication {
    
    public static void main(String[] args) {
         SpringApplication.run(BatApplication.class, args);
    }
    
}

application.yml配置文件

# MyBatis
    mybatis:
    # 数据库映射实体类包路径 type-aliases-package: com.kinson.comm.domain mapper-locations: classpath:/mybatis/*.xml

启动项目

扫描二维码关注公众号,回复: 7367266 查看本文章

访问测试url

可以看到访问comm的接口成功

Springboot集成mybaits源码参照

Github spring boot 配置访问其他模块包中的mapper和xml源码参照

猜你喜欢

转载自www.cnblogs.com/kingsonfu/p/11590219.html