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 多库部署方式的更多相关文章

  1. Spring MVC 前后端 Json 方式交互和处理

    众所周知,在mvc中,数据是在各个层次之间进行流转是一个不争的事实. 而这种流转,也就会面临一些困境,这些困境,是由于数据在不同世界中的表现形式不同而造成的.   数据在页面上是一个扁平的,不带数据类 ...

  2. Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法

    Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法 在Action中方法的返回值都是字符串行,一般情况是返回某个JSP,如: return "xx" ...

  3. mybatis实战教程(mybatis in action)之六:与Spring MVC 的集成

    前面几篇文章已经讲到了mybatis与spring 的集成.但这个时候,所有的工程还不是web工程,虽然我一直是创建的web 工程.今天将直接用mybatis与Spring mvc 的方式集成起来,源 ...

  4. Spring MVC 的 XML 配置方式

    索引: 开源Spring解决方案--lm.solution 参看代码 GitHub: solution/pom.xml solution/webapi/pom.xml solution/mapper/ ...

  5. Mybatis学习(6)与Spring MVC 的集成

    前面几篇文章已经讲到了mybatis与spring 的集成.但这个时候,所有的工程还不是web工程,虽然我一直是创建的web 工程.今天将直接用mybatis与Spring mvc 的方式集成起来,源 ...

  6. Spring MVC拦截器+注解方式实现防止表单重复提交

    原理:在新建页面中Session保存token随机码,当保存时验证,通过后删除,当再次点击保存时由于服务器端的Session中已经不存在了,所有无法验证通过. 注,如果是集群的方式,则需要将token ...

  7. spring mvc 异常统一处理方式

    springMVC提供的异常处理主要有两种方式: 一种是直接实现自己的HandlerExceptionResolver: 另一种是使用注解的方式实现一个专门用于处理异常的Controller——Exc ...

  8. Spring MVC Controller中GET方式传过来的中文参数会乱码的问题

    Spring MVC controller 这样写法通常意味着访问该请求,GET和POST请求都行,可是经常会遇到,如果碰到参数是中文的,post请求可以,get请求过来就是乱码.如果强行对参数进行了 ...

  9. html form method 属性不支持put,delete请求方式,以及开启spring mvc的rest的方式

    1.加上隐藏域解决form method 不支持put,delete的请求方式的问题 2.配置spring mvc HiddenHttpMethodFilter过滤器实现对put和delete请求方式 ...

  10. spring mvc 多库连接

    最近弄了个spring mvc + hibernate4为框架的项目,其中需用到其他两个库的数据.具体如下: 1.将两库的application文件配置好,需注意的地方是两个事务控制是不一样的. 和 ...

随机推荐

  1. Make a plan, and stand for it!

    我发现博主本人善于事前做计划,事后做总结.但是不善于坚持自己的计划.就拿10.1这个假期来讲,放假前看多许多的攻略,计划了很多条的自驾出行的路线,但是好像一条也没坚持,最后选择了一条临时的线路,而且临 ...

  2. shell :将标准输出及标准错误输出写到指定文件

    shell 脚本如下: logFile=/usr/local/log/$today.txt exec >> $logFile 2>&1 1为标准输出stdout.2为标准错误 ...

  3. 爬虫基础线程进程学习-Scrapy

    性能相关 学习参考:http://www.cnblogs.com/wupeiqi/articles/6229292.html 在编写爬虫时,性能的消耗主要在IO请求中,当单进程单线程模式下请求URL时 ...

  4. suricata HTTP关键字

    http request http request请求包括请求行.请求头.空行和内容.一个普通的request请求如下: http response http response应答包括应答行,头部,空 ...

  5. spring boot 常见三十四问

    Spring Boot 是微服务中最好的 Java 框架. 我们建议你能够成为一名 Spring Boot 的专家. 问题一 Spring Boot.Spring MVC 和 Spring 有什么区别 ...

  6. python学习笔记_week27

    search import time import random def cal_time(func): def wrapper(*args, **kwargs): t1 = time.time() ...

  7. python至winreg模块

    _winreg模块在python3中已经改名了 https://blog.csdn.net/zhangxiaoyang0/article/details/72236305?fps=1&loca ...

  8. django-内网项目上线测试部署步骤

    1.安装python环境 由于测试环境只有内网,所以在外网同系统上安装python. wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5 ...

  9. 楚乔传 Princess Agents

    英文片名是:Princess Agents 公主特工,哈哈,女主角是公主...所有隐藏的线索都暴露了...这么搞笑呢.

  10. python入门(一):进入python的交互模式、pip的使用和数据类型

    环境安装: https://www.python.org/ pycharm 社区版路径: http://www.jetbrains.com/pycharm/download/download-than ...