zoukankan      html  css  js  c++  java
  • 一次多数据源 配置问题记录

      现在的项目是个多数据源的配置,前两天 做项目迁移,要把另一个项目迁移到api的项目里面。于是 粘贴复制后,发现不能运行。。。 最后发现是多数据源配置出了问题。

      

    <?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:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
         http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
        <!-- 配置datasource数据源(主库)  -->
        <bean id="taxi-master-DataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close" parent="commonsAbstractDataSource">
            <property name="url" value="${taxi.master.jdbc.url}"/>
            <property name="username" value="${taxi.master.jdbc.username}"/>
            <property name="password" value="${taxi.master.jdbc.password}"/>
        </bean>
        <!-- 配置datasource数据源(从库)  -->
        <bean id="taxi-slave-DataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close" parent="commonsAbstractDataSource">
            <property name="url" value="${taxi.slave.jdbc.url}"/>
            <property name="username" value="${taxi.slave.jdbc.username}"/>
            <property name="password" value="${taxi.slave.jdbc.password}"/>
        </bean>
        <!-- 配置datasource数据源(支持动态主从库切换,ID属性即为动态路由数据源标识名)  -->
        <bean id="taxi-DataSource" class="com.zhuanche.common.database.DynamicRoutingDataSource">
           <!-- 默认目标数据源为主库 -->
           <property name="defaultTargetDataSource" ref="taxi-master-DataSource"/>
           <!-- 所有目标数据源 -->
           <property name="targetDataSources">
               <map key-type="java.lang.String">
                   <entry key="master" value-ref="taxi-master-DataSource"/>
                   <entry key="slave" value-ref="taxi-slave-DataSource"/>
               </map>
           </property>
        </bean>    
    
        <!-- 配置SqlSessionFactory -->
        <bean id="taxi-sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="taxi-DataSource" />
            <!-- 请修改此处:修改为实际的数据对象包路径 -->
            <property name="typeAliasesPackage" value="com.zhuanche.entity.taxi" />
            <!-- 请修改此处: 请修改为实际的mybatis环境配置文件位置 -->
            <property name="configLocation" value="classpath:mybatis-conf.xml" />
            <!-- 分页插件 -->
            <property name="plugins">
                <array>
                    <bean class="com.github.pagehelper.PageInterceptor">
                        <!-- 这里的几个配置主要演示如何使用,如果不理解,一定要去掉下面的配置 -->
                        <property name="properties">
                            <value>
                                helperDialect=mysql
                                reasonable=false
                                supportMethodsArguments=true
                                params=count=countSql
                                autoRuntimeDialect=true
                            </value>
                        </property>
                    </bean>
                </array>
            </property>
        </bean>
    
        <!-- 配置mapper扫描 -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
           <property name="sqlSessionFactoryBeanName" value="taxi-sqlSessionFactory"></property>
            <!-- 请修改此处: 请修改为实际的mapper接口包路径 -->
            <property name="basePackage" value="mapper.taxi" />
        </bean>
    
    </beans>

        注意 加红的部门。自己就是在这个地方出错了。。。导致 数据库一直读取不到。

  • 相关阅读:
    数据库中两张表之间的数据同步实现思路(增加、删除、更新)Mysql、sqlserver
    多台服务器之间如何让sqlserver,mysql数据库进行数据同步?
    mysql数据库同步时数据一致性的配置优化
    mysql 、sqlserver数据库,实时同步,增量同步(脚本模式)
    SyncNavigator 注册机 使用教程
    SyncNavigator数据库同步软件8.4.1 中文版
    HKROnline SyncNavigator破解版企业版 8.4.1 注册机使用教程
    SyncNavigator 破解版8.4.1 企业版 授权注册流程
    浅谈数据库高可用性(HA)技术
    软件工程第七周总结
  • 原文地址:https://www.cnblogs.com/thinkingandworkinghard/p/9822155.html
Copyright © 2011-2022 走看看