<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- 加载jdbc.properties文件 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:config/datasource.properties</value>
</list>
</property>
</bean> <!-- 配置DataSource数据源 -->
<!-- <bean id="dataSource" -->
<!-- class="org.springframework.jdbc.datasource.DriverManagerDataSource"> -->
<!-- <property name="driverClassName" value="${driver}" /> -->
<!-- <property name="url" value="${url}" /> -->
<!-- <property name="username" value="${username}" /> -->
<!-- <property name="password" value="${password}" /> -->
<!-- </bean> --> <!-- JNDI连接池配置(jboss:java:/socket tomcat : java:comp/env/jdbc/socket)-->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/socket</value>
</property>
</bean> <!-- 配置Mybatis SqlSessionFactoryBean -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:config/mybatis.xml" />
<!-- mapper和resultmap配置路径 -->
<property name="mapperLocations">
<list>
<!-- 表示在com/smart/包或以下所有目录中,以_sql.xml结尾所有文件 -->
<value>classpath*:com/bd/**/*_sql.xml</value>
</list>
</property>
</bean> <!-- 框架 -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean> <bean id="dataSourceHr" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/hr</value>
</property>
</bean> <!-- 配置Mybatis SqlSessionFactoryBean -->
<bean id="sqlSessionFactoryHr" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceHr" />
<property name="configLocation" value="classpath:config/mybatis.xml" />
<!-- mapper和resultmap配置路径 -->
<property name="mapperLocations">
<list>
<!-- 表示在com/smart/包或以下所有目录中,以_sql.xml结尾所有文件 -->
<value>classpath*:com/bd/**/*_sql.xml</value>
</list>
</property>
</bean> <!-- 框架 -->
<bean id="sqlSessionHr" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactoryHr" />
</bean> <bean id="batisDao" class="com.bd.core.base.dao.mybatis.BatisDaoImpl">
<property name="sqlSession">
<ref bean="sqlSession" />
</property>
<property name="sqlSessionHr">
<ref bean="sqlSessionHr" />
</property>
</bean> <!--事务相关控制-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean> <tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" propagation="REQUIRED"
rollback-for="Exception,BusinessException" />
<tx:method name="find*" propagation="REQUIRED"
rollback-for="Exception,BusinessException" />
<tx:method name="query*" propagation="REQUIRED"
rollback-for="Exception,BusinessException" />
<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception,BusinessException" />
<tx:method name="save*" propagation="REQUIRED"
rollback-for="Exception,BusinessException" />
<tx:method name="update*" propagation="REQUIRED"
rollback-for="Exception,BusinessException" />
<tx:method name="edit*" propagation="REQUIRED"
rollback-for="Exception,BusinessException" />
<tx:method name="delete*" propagation="REQUIRED"
rollback-for="Exception,BusinessException" />
<tx:method name="remove*" propagation="REQUIRED"
rollback-for="Exception,BusinessException" />
<tx:method name="audit*" propagation="REQUIRED"
rollback-for="Exception,BusinessException" />
<tx:method name="modify*" propagation="REQUIRED"
rollback-for="Exception,BusinessException" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="interceptorPointCuts"
expression="execution(* com.bd.smart.*.*.service..*.*(..)) || execution(* com.bd.smart.*.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" />
</aop:config> </beans>

配置两个数据源和session工厂类和session对象,只需在dao的bean 中注入这些session对象,当调用的是哪个session 就会获取哪个数据库的连接。

ssm 配置多个数据源的更多相关文章

  1. ssm框架使用详解&配置两个数据源

    学习ssm框架已经快一年了,今天把这个框架总结一下. SSM 就是指 spring.SpringMVC和Mybatis.先说一下基本概念(百度上搜的) 1.基本概念 1.1.Spring Spring ...

  2. ssm项目配置多个数据源

    在项目中到一些问题,一些查询模块需要链接另一个数据库,这时,就可以配置两个数据源进行操作. 1.创建jdbc.properties jdbc.url = jdbc:mysql://localhost: ...

  3. spring-data-mongodb一个系统xml文件里面配置两个数据源

    spring-data-mongodb一个系统xml文件里面配置两个数据源 参考文档如下: http://www.iteye.com/problems/92789 http://stackoverfl ...

  4. 用JAVA代码获取Weblogic配置的JNDI 数据源连接

    第一步:生成与JDK版本对应的weblogicjar,利用cmd 进入到weblogic_home 路径下进入到server/lib目录,然后运行  JDK  1.6 命令 "java -j ...

  5. SpringMVC+Mybatis 如何配置多个数据源并切换?

    最近公司一个项目需要连接两个数据库(A和B)操作,有的模块查询A库,有的模块查询B库,因此需要改造下,项目后台用的是SpringMVC+Mybatis+MySQL架构,折腾了两天后终于搞定了,在这里记 ...

  6. SpringBoot入门之基于Druid配置Mybatis多数据源

    上一篇了解了Druid进行配置连接池的监控和慢sql处理,这篇了解下使用基于基于Druid配置Mybatis多数据源.SpringBoot默认配置数据库连接信息时只需设置url等属性信息就可以了,Sp ...

  7. 20. Spring Boot 默认、自定义数据源 、配置多个数据源 jdbcTemplate操作DB

    Spring-Boot-2.0.0-M1版本将默认的数据库连接池从tomcat jdbc pool改为了hikari,这里主要研究下hikari的默认配置 0.  创建Spring Boot项目,选中 ...

  8. 配置多个数据源,spring profile 多环境配置管理

    针对生产环境,测试环境,以及本地调试开发有时会配置多套数据库,在一个数据配置文件进行修改,往往有时发布到生成环境会忘记修改,或者本地调试时还是生产环境的库,会导致生产环境数据被污染. ps--刚开始配 ...

  9. Springbooot +Mybaties 配置数据库多数据源

    前言 在实际项目中,我们可能会碰到在一个项目中会访问多个数据库的情况.针对这种情况,我们就需要配置动态的数据源了.一般按照以下步骤即可 一.在启动类上添加注解 二.在application.prope ...

随机推荐

  1. Ubuntu下忘记MySQL root密码解决方法

    1.忘了mysql密码,从网上找到的解决方案记录在这里. 编辑mysql的配置文件/etc/mysql/my.cnf,在[mysqld]段下加入一行“skip-grant-tables”. 2.重启服 ...

  2. CF-877E-线段树+哈希

    http://codeforces.com/problemset/problem/877/E 给出一颗有根树,没个节点上有一个值0/1,有两种操作,一个是选中一个节点,对他所对应的那个子树上所有节点的 ...

  3. ALV打印模板(存代码)

    *&---------------------------------------------------------------------* *& Report ZMMF013 * ...

  4. 微信小程序页面无法跳转

    推荐网址:https://www.jianshu.com/p/e56b55334585 1.无法跳转原因分析 要跳转的路径在app.js里未注册过或路径写错   要跳转的路径是否位于TabBar中 页 ...

  5. 动态规划入门——数字三角形(Java)

    动态规划的概念对于新手来说枯燥难懂,就算看懂了,做题的时候依旧抓耳挠腮的毫无头绪,这些比较难理解的算法,还是需要根据例子来一步步学习和理解,从而熟练掌握,下面,咱们就通过一个简单的小例子来学习动态规划 ...

  6. Java 9中新的货币API

    译文出处: Java译站   原文出处:Michael Scharhag JSR 354定义了一套新的Java货币API,计划会在Java 9中正式引入.本文中我们将来看一下它的参考实现:JavaMo ...

  7. 基本git指令

    --git包含命令行界面和图形化界面 1.Git安装之后需要进行一些基本信息设置 a.设置用户名:git  config -- global  user.name  '你再github上注册的用户名' ...

  8. MySQL(二) MySQL基本操作

    数据库的基本操作 启动关闭 MySQL 服务 MySQL 安装好后,默认是当 Windows 启动.停止时,MySQL 也自动.停止.不过,用户可以使用 Windows 下的服务管理器或从命令行使用 ...

  9. 逆袭之旅DAY24.XIA.二重进阶、双色球

    一. 选择题. 1. 以下关于二重循环的说法正确的是(D). A. 二重循环就是一般程序中只能有两个循环 B. While循环不能嵌套在for循环里 C. 两个重叠的循环不能嵌套在第三个循环里. D. ...

  10. Win10系列:VC++媒体播放控制1

    在MediaElement控件中定义了用于控制视频播放的函数,如Play.Pause和Stop等函数.本小节将在20.6.1小节所新建的项目基础上继续来介绍如何为视频添加播放控制,并在最后一部分给出项 ...