采用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. php权限管理

    首先权限管理肯定是需要登陆的,这里就简单的写一个登陆页面. 简单的登陆页面login.php <h1>登录页面</h1> <form action="login ...

  2. English-培训2-五大句型

  3. HTML5 - 初识

    众所周知,我们现在的手机APP开发模式分为一下几大类: 一.原生APP 二.纯HTML5 三.原生+HTML5 四.React Native 公司的职位划分: 1.平面设计师  : 作图.切图.HTM ...

  4. SQLSEVER 同台服务器下不同表 触发器实现数据实时同步

    触发器的使用: 1.首先建立两个相同结构的表,两个表明的列的名称不同. student_01   字段  name  ;  字段 age  ; 字段  class ; student_02   字段  ...

  5. outlook配置其他邮箱登录如qq邮箱或登录无邮件信息记录

    今天加班想想自己outlook还没登登录过,于是想着登录一下outlook方便管理邮箱信息,才发现原来登录邮箱都要配置,感觉真是醉了.下面开始正式的配置流程. 选择添加账户 首先,点击文件选择账户设置 ...

  6. Vue框架之初识

    介绍 vue.js 是用来构建web应用接口的一个库 技术上,Vue.js 重点集中在MVVM模式的ViewModel层,它连接视图和数据绑定模型通过两种方式.实际的DOM操作和输出格式被抽象的方式到 ...

  7. python编码和解码

    一.什么是编码 编码是指信息从一种形式或格式转换为另一种形式或格式的过程. 在计算机中,编码,简而言之,就是将人能够读懂的信息(通常称为明文)转换为计算机能够读懂的信息.众所周知,计算机能够读懂的是高 ...

  8. php 图片与base64互转

    header('Content-type:text/html;charset=utf-8'); //读取图片文件,转换成base64编码格式 $image_file = '1.png'; $image ...

  9. request-html模块 (上)

    requests-html模块 官方网站 Github网址 请求数据 from requests_html import HTMLSession session = HTMLSession() req ...

  10. Linux命令——killall 、kill 、pkill、xkill

    参考:killall .kill .pkill 命令详解 Using kill, killall, and pkill 4 Ways to Kill a Process – kill, killall ...