MyBatis-Plus 多库部署方式;spring mvc 多库部署方式
1、实现mybatis-plus的多个数据库的切换方式
源码地址:https://github.com/baomidou/mybatisplus-spring-mvc
2、因为其文档都是相互依赖的,所以修改配置,就是在已有的配置中修改
这里配置多数据源采用定义不同的profile方式修改启动时连接的数据库
原版
配置文件位置:https://github.com/baomidou/mybatisplus-spring-mvc/tree/master/src/main/resources/spring
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <!-- 引入属性文件 -->
<context:property-placeholder location="classpath:config.properties"/> <!-- Service包(自动注入) -->
<context:component-scan base-package="com.baomidou.springmvc.service"/> <import resource="classpath:spring/spring-mybatis.xml"/>
</beans>
修改后配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd" profile="development"> <!-- 引入属性文件 -->
<!--<context:property-placeholder location="classpath:applicationContext-profile.xml"/>-->
<!--<context:property-placeholder location="classpath:config.properties"/>--> <beans profile="development">
<context:property-placeholder
location="classpath*:common/*.properties,classpath*:development/*.properties"/>
<!-- Service包(自动注入) -->
<!-- 修改了package路径 -->
<context:component-scan base-package="com.rent.springmvc.service"/>
<!--导入mybatis-->
<import resource="classpath:spring/spring-mybatis.xml"/>
</beans> <!-- 测试环境配置文件 -->
<beans profile="test">
<context:property-placeholder
location="classpath*:common/*.properties,classpath*:test/*.properties"/> <!-- Service包(自动注入) -->
<!-- 修改了package路径 -->
<context:component-scan base-package="com.rent.springmvc.service"/>
<!--导入mybatis-->
<import resource="classpath:spring/spring-mybatis.xml"/>
</beans> <!-- 生产环境配置文件 -->
<beans profile="production">
<context:property-placeholder
location="classpath*:common/*.properties,classpath*:production/*.properties"/> <!-- Service包(自动注入) -->
<!-- 修改了package路径 -->
<context:component-scan base-package="com.rent.springmvc.service"/>
<!--导入mybatis-->
<import resource="classpath:spring/spring-mybatis.xml"/>
</beans> </beans>
项目路径截图

development中写修改的
validationQuery=SELECT 1
###############本地数据库
jdbc_url=jdbc\:mysql\://localhost\:3306/renttest?characterEncoding\=UTF-8
##jdbc_url=jdbc\:mysql\://192.168.31.255\:3306/test?characterEncoding\=UTF-8
jdbc_username=root
jdbc_password=123456
3、beans可以嵌套beans,这是核心配置
<beans profile="development">
<context:property-placeholder
location="classpath*:common/*.properties,classpath*:development/*.properties"/>
<!-- Service包(自动注入) -->
<!-- 修改了package路径 -->
<context:component-scan base-package="com.rent.springmvc.service"/>
<!--导入mybatis-->
<import resource="classpath:spring/spring-mybatis.xml"/> </beans>
import引入其他配置,这是一份拼接的配置文件
MyBatis-Plus 多库部署方式;spring mvc 多库部署方式的更多相关文章
- Spring MVC 前后端 Json 方式交互和处理
众所周知,在mvc中,数据是在各个层次之间进行流转是一个不争的事实. 而这种流转,也就会面临一些困境,这些困境,是由于数据在不同世界中的表现形式不同而造成的. 数据在页面上是一个扁平的,不带数据类 ...
- Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法
Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法 在Action中方法的返回值都是字符串行,一般情况是返回某个JSP,如: return "xx" ...
- mybatis实战教程(mybatis in action)之六:与Spring MVC 的集成
前面几篇文章已经讲到了mybatis与spring 的集成.但这个时候,所有的工程还不是web工程,虽然我一直是创建的web 工程.今天将直接用mybatis与Spring mvc 的方式集成起来,源 ...
- Spring MVC 的 XML 配置方式
索引: 开源Spring解决方案--lm.solution 参看代码 GitHub: solution/pom.xml solution/webapi/pom.xml solution/mapper/ ...
- Mybatis学习(6)与Spring MVC 的集成
前面几篇文章已经讲到了mybatis与spring 的集成.但这个时候,所有的工程还不是web工程,虽然我一直是创建的web 工程.今天将直接用mybatis与Spring mvc 的方式集成起来,源 ...
- Spring MVC拦截器+注解方式实现防止表单重复提交
原理:在新建页面中Session保存token随机码,当保存时验证,通过后删除,当再次点击保存时由于服务器端的Session中已经不存在了,所有无法验证通过. 注,如果是集群的方式,则需要将token ...
- spring mvc 异常统一处理方式
springMVC提供的异常处理主要有两种方式: 一种是直接实现自己的HandlerExceptionResolver: 另一种是使用注解的方式实现一个专门用于处理异常的Controller——Exc ...
- Spring MVC Controller中GET方式传过来的中文参数会乱码的问题
Spring MVC controller 这样写法通常意味着访问该请求,GET和POST请求都行,可是经常会遇到,如果碰到参数是中文的,post请求可以,get请求过来就是乱码.如果强行对参数进行了 ...
- html form method 属性不支持put,delete请求方式,以及开启spring mvc的rest的方式
1.加上隐藏域解决form method 不支持put,delete的请求方式的问题 2.配置spring mvc HiddenHttpMethodFilter过滤器实现对put和delete请求方式 ...
- spring mvc 多库连接
最近弄了个spring mvc + hibernate4为框架的项目,其中需用到其他两个库的数据.具体如下: 1.将两库的application文件配置好,需注意的地方是两个事务控制是不一样的. 和 ...
随机推荐
- wordpress 解决文章内http链接问题
1. 登录Wordpress后台, 常规设置 > 里面把站点URL 修改成 https开头 2. 登录phpmyadmin , 执行替换链接的SQL 替换wordpress配置的链接地址 (可 ...
- c# 对象的深拷备
C# 引用类型对象在拷备时,一般有浅拷备与深拷备,浅拷备指向的是同一对象的引用地址,一个对象的修改必然会影响另一个对象,而深拷备是直接拷备对象的内容,而不是引用,拷备后的对象拥有新的引用,这里主要介绍 ...
- [java,2017-05-15] 内存回收 (流程、时间、对象、相关算法)
内存回收的流程 java的垃圾回收分为三个区域新生代.老年代. 永久代 一个对象实例化时 先去看伊甸园有没有足够的空间:如果有 不进行垃圾回收 ,对象直接在伊甸园存储:如果伊甸园内存已满,会进行一次m ...
- matlab-可视化图像阈值选择GUI工具
话不多说,先看图,这是导入一张图后运行的效果. 在此函数中,左图是灰度图加上colorBar后的彩色效果图,右图是二值化后的图,下面是可调节阈值的灰度直方图. 左上角的按钮是回归初始状态,右上角的按钮 ...
- ZIP压缩输入/输出流
ZIP是压缩文件的格式,使用ZIP可以节省空间 java将压缩/解压缩文件的方法都封装在java.util.zip包下,java实现了I/O数据流和网络数据流的单一接口,所以实现起来比较容易. 主要的 ...
- 接口自动化测试链接https://www.cnblogs.com/finer/
https://www.cnblogs.com/finer/ 测试框架的基本原则:业务逻辑与测试脚本分离,测试脚本与测试数据分离: 接口自动化的两种方式:工具(jmeter).代码(使用的是pytho ...
- CSS 图像居中对齐
CSS 图像居中对齐 我们在<CSS 内外边距>学过内容居中,它的原理是将外边左右设置为auto.图像居中也是这个原理. 示例 <!DOCTYPE html> <htm ...
- react-native 新手爬坑经历(unable to load script from assets 和could not connect to development server.)
按照https://reactnative.cn/docs/0.51/getting-started.html教程新建的项目 react-native init AwesomeProject cd A ...
- 关于echarts图表在tab页中width:100%失效的问题
https://www.cnblogs.com/tongrenlu/p/9268250.html
- http://ctf.bugku.com/challenges#love:bugku--love
做了一道逆向题目,主要关联到base64编码的知识点.下面做一分析. 题目如下: 通过测试,可知它没有加壳.尝试使用IDA进行分析. 1.IDA分析文件 打开文件后,按[shift+F12 ...