Spring boot + mybatis 只读取到一个jar包中的mapper配置文件
采用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配置文件的更多相关文章
- 搜索某个目录下所有jar包中的mapper目录下的xml文件
rm -rf /mapper/* find /data/app/app-*/lib ! -path "*xnpush*" ! -path "*portal*" ...
- spring加载jar包中多个配置文件(转)
转自:http://evan0625.iteye.com/blog/1598366 在使用spring加载jar包中的配置文件时,不支持通配符,需要一个一个引入,如下所示: Java代码 <co ...
- Spring、MyBatis和SpringMVC整合的jar包下载
spring mvc的jar包下载:http://repo.springsource.org/libs-release-local/org/springframework/spring/我下载的5.0 ...
- Spring Boot 的项目打包成的 JAR 包,制作成 docker 镜像并运行
上一篇:Docker学习(三)docker容器操作 首先把本地的项目打包好,我这里直接把已经打包好的springboot-mybatis-0.0.1-SNAPSHOT.jar包直接上传到linuxmy ...
- spring加载jar包中多个配置文件
转自:http://www.cnblogs.com/GarfieldTom/p/3723915.html <import resource="classpath*:applicatio ...
- spring加载jar包中多个配置文件(转载)
本文转载自:http://www.cnblogs.com/GarfieldTom/p/3723915.html
- (5)java Spring Cloud+Spring boot+mybatis企业快速开发架构之SpringCloud-Spring Boot简介
Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式进行配置,从而使开发人员不再需要定义样板化的配置 ...
- spring boot通过@Bean注解定义一个Controller
功能需求 提供一个公共的jar包给其他业务模块依赖,需要在这个公共的jar中暴露一个restful API 采用spring auto config机制,在公共jar包中定义spring.factor ...
- Maven将代码及依赖打成一个Jar包的方式
Maven可以使用mvn package指令对项目进行打包,如果使用java -jar xxx.jar执行运行jar文件,会出现"no main manifest attribute, in ...
随机推荐
- Android Studio 生成 keystore 签名文件
Android Studio 生成 keystore 签名文件 常见 SSL 证书格式 : .DER .CER,文件是二进制格式,只保存证书,不保存私钥. .PEM,一般是文本格式,可保存证书,可保存 ...
- Django Rest framework的限流实现流程
目录 一 什么是throttle 二 Django REST framework是如何实现throttle的 三 Django REST framework中throttle源码流程 一 什么是thr ...
- 【转载】网站配置Https证书系列(二):IIS服务器给网站配置Https证书
针对网站的Https证书,即SSL证书,腾讯云.阿里云都提供了免费的SSL证书申请,SSL证书申请下来后,就需要将SSL证书配置到网站中,如果网站使用的Web服务器是IIS服务器,则需要在IIS服务器 ...
- shell 三剑客之 sed 命令详解
sed 编辑命令 sed 编辑命令对照表 把 /etc/passwd 文件赋值到当前路径下,进行操作 cp /etc/passwd ./ cat -n passwd sed 删除操作 删除 passw ...
- java.lang.NoClassDefFoundError: Could not initialize class xxx
感慨:啊啊啊啊啊啊啊啊啊啊,这个问题弄了我好久,整整一天!!! 概述:原本是调用公司自己写的jar包的工具类.在其他项目都能调用,一模一样的套用过来就是不行.问了一些同事他们也不知道怎么解决. 然后百 ...
- 利用 Python django 框架 输入汉字,数字,字符,等。。转成二维码!
利用 Python django 框架 输入汉字,数字,字符,等..转成二维码! 模块必备:Python环境 + pillow + qrcode 模块 核心代码import qrcode qr = ...
- unittest 运行slenium(四)---通过指定用例的形式运行用例
一: 说明 跟数据驱动唯一的区别为用例数据获取时,及运行方式不同. 其它都基本相同,可参考https://www.cnblogs.com/xiaodingdong/p/11753220.html 二: ...
- spice在桌面虚拟化中的应用系列之一(spice简介,性能优化等)
1.spice介绍 1.1 spice简介 spice是由Qumranet开发的开源网络协议,2008年红帽收购了Qumranet获得了这个协议.SPICE是红帽在虚拟化领域除了KVM的又一“新兴技术 ...
- SUSE SLES15SP1 高可用(HA)- 快速安装和设置
- 第七届蓝桥杯C/C++程序设计本科B组决赛 ——棋子换位(代码补全题)
棋子换位 有n个棋子A,n个棋子B,在棋盘上排成一行.它们中间隔着一个空位,用“.”表示,比如: AAA.BBB 现在需要所有的A棋子和B棋子交换位置.移动棋子的规则是:1. A棋子只能往右边移动,B ...