采用spring boot  开发了一个多模块项目,有多个模块中都有mapper配置文件。

采用如下的方式配置,制度去到了一个模块jar包中配置文件:

  @Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean() {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setTypeAliasesPackage("tk.mybatis.springboot.model");
MybatisInterceptor interceptor = new MybatisInterceptor();
bean.setPlugins(new Interceptor[]{interceptor}); //添加XML目录
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
try {
//\com\tritrust\t\core\dict\sqlmap
//\com\tritrust\t\system\sqlmap
bean.setMapperLocations(resolver.getResources("classpath:com/tritrust/t/**/sqlmap/*.xml"));
return bean.getObject();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

需要读取多个jar里面的配置需要修改配置路径为:

bean.setMapperLocations(resolver.getResources("classpath*:com/tritrust/t/**/sqlmap/*.xml"));
classpath*:就可以读取多个jar里面文件了。

查看spring core 中org.springframework.core.io.support.PathMatchingResourcePatternResolver类有如下代码:
    public Resource[] getResources(String locationPattern) throws IOException {
Assert.notNull(locationPattern, "Location pattern must not be null");
if (locationPattern.startsWith("classpath*:")) {
return this.getPathMatcher().isPattern(locationPattern.substring("classpath*:".length())) ? this.findPathMatchingResources(locationPattern) : this.findAllClassPathResources(locationPattern.substring("classpath*:".length()));
} else {
int prefixEnd = locationPattern.startsWith("war:") ? locationPattern.indexOf("*/") + 1 : locationPattern.indexOf(58) + 1;
return this.getPathMatcher().isPattern(locationPattern.substring(prefixEnd)) ? this.findPathMatchingResources(locationPattern) : new Resource[]{this.getResourceLoader().getResource(locationPattern)};
}
}
												

Spring boot + mybatis 只读取到一个jar包中的mapper配置文件的更多相关文章

  1. 搜索某个目录下所有jar包中的mapper目录下的xml文件

    rm -rf /mapper/* find /data/app/app-*/lib ! -path "*xnpush*" ! -path "*portal*" ...

  2. spring加载jar包中多个配置文件(转)

    转自:http://evan0625.iteye.com/blog/1598366 在使用spring加载jar包中的配置文件时,不支持通配符,需要一个一个引入,如下所示: Java代码 <co ...

  3. Spring、MyBatis和SpringMVC整合的jar包下载

    spring mvc的jar包下载:http://repo.springsource.org/libs-release-local/org/springframework/spring/我下载的5.0 ...

  4. Spring Boot 的项目打包成的 JAR 包,制作成 docker 镜像并运行

    上一篇:Docker学习(三)docker容器操作 首先把本地的项目打包好,我这里直接把已经打包好的springboot-mybatis-0.0.1-SNAPSHOT.jar包直接上传到linuxmy ...

  5. spring加载jar包中多个配置文件

    转自:http://www.cnblogs.com/GarfieldTom/p/3723915.html <import resource="classpath*:applicatio ...

  6. spring加载jar包中多个配置文件(转载)

    本文转载自:http://www.cnblogs.com/GarfieldTom/p/3723915.html

  7. (5)java Spring Cloud+Spring boot+mybatis企业快速开发架构之SpringCloud-Spring Boot简介

    ​Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式进行配置,从而使开发人员不再需要定义样板化的配置 ...

  8. spring boot通过@Bean注解定义一个Controller

    功能需求 提供一个公共的jar包给其他业务模块依赖,需要在这个公共的jar中暴露一个restful API 采用spring auto config机制,在公共jar包中定义spring.factor ...

  9. Maven将代码及依赖打成一个Jar包的方式

    Maven可以使用mvn package指令对项目进行打包,如果使用java -jar xxx.jar执行运行jar文件,会出现"no main manifest attribute, in ...

随机推荐

  1. [JZOJ5281]钦点题解--瞎搞+链表

    [JZOJ5281]钦点题解--瞎搞+链表 题目链接 于 暴 力 过

  2. 加快JavaScript加载和执行效率

    JavaScript 在浏览器中的性能成为开发者所面临的最重要的可用性问题.而这个问题又因 JavaScript 的阻塞特性变的复杂,也就是说当浏览器在执行 JavaScript 代码时,不能同时做其 ...

  3. va_start可变参数函数

    void va_start(va_list ap, last); //变参起始地址 type va_arg(va_list ap, type); //下一个参数的地址 void va_end(va_l ...

  4. git的下载和安装

    Git 安装配置 在使用Git前我们需要先安装 Git.Git 目前支持 Linux/Unix.Solaris.Mac和 Windows 平台上运行. Git 各平台安装包下载地址为:http://g ...

  5. CSS之特性相关

    一.css的继承性与层叠性 继承性: 面向对象语言都会存在继承的概念,在面向对象语言中,继承的特点:继承了父类的属性和方法.那么我们现在主要研究css,css就是在设置属性的.不会牵扯到方法的层面. ...

  6. django 配置文件settings.py 设置模板

    INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'dj ...

  7. webpack多页面打包配置

    单页面应用:整个应用里面只有一个html文件.现在主流的框架,vue,react都是单页面应用. 所以webpack绝大部分都是对单页面打包.那么webpack如何对多页面进行打包 index.htm ...

  8. 17 webpack中babel的配置——静态属性与实例属性

    // class关键字,是ES6中提供的新语法,是用来实现ES6中面向对象编程的方式 class Person{ // 使用static关键字,可以定义静态属性 // 所谓的静态属性,就是可以直接通过 ...

  9. 15 webpack中使用url-loader处理字体文件

    引用字体图标,bootstrap有提供字体图标 1.安装bootstrap cnpm i bootstrap -S 2.导入bootstrap //注意:如果要通过路径的形式,去引入node_modu ...

  10. BLOB和TEXT

    区别: BLOB存储的是二进制数据,没有排序规则或字符集. TEXT存储的是字符,有排序规则和字符集. 因为Memory引擎不支持BLOB和TEXT类型,最好的解决方案避免使用BLOB和TEXT类型. ...