日期:2014-05-18  浏览次数:20778 次

关于Spring+hibernate动态链接多个数据库
 想使用spring+Hibernate框架,连接多个数据库。网上有一些资料算是比较成熟的解决方案,大概是实现抽象类AbstractRoutingDataSource,将多个数据库的连接写成bean;sessionFactory使用 自己实现的类。具体的配置文件如下:
<beans>
       <bean id="master"
              class="com.mchange.v2.c3p0.ComboPooledDataSource"
              destroy-method="close">
              <property name="driverClass">
                     <value>com.mysql.jdbc.Driver</value>
              </property>
              <property name="jdbcUrl">
                     <value>jdbc:mysql://192.168.18.143:3306/wenhq?useUnicode=true&amp;characterEncoding=utf-8</value>
              </property>
              <property name="user">
                     <value>root</value>
              </property>
              <property name="password">
                     <value></value>
              </property>
       </bean>
       <bean id="slave"
              class="com.mchange.v2.c3p0.ComboPooledDataSource"
              destroy-method="close">
              <property name="driverClass">
                     <value>com.mysql.jdbc.Driver</value>
              </property>
              <property name="jdbcUrl">
                     <value>jdbc:mysql://192.168.18.144:3306/ wenhq?useUnicode=true&amp;characterEncoding=utf-8</value>
              </property>
              <property name="user">
                     <value>root</value>
              </property>