多数据源



































       
           
               
               
           

       

       
   



p:dataSource-ref="dataSource" p:mapperLocations="/WEB-INF/orm/**/*.xml" />



p:sqlSessionFactoryBeanName="sqlSessionFactory" />




p:dataSource-ref="dataSource" />






















package com.msuisoft.rbook.student.controller;


import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;


public class DynamicDataSource extends AbstractRoutingDataSource{
public static final String DATA_SOURCE_ORACLE = "oracle";
        public static final String DATA_SOURCE_MYSQL = "mysql";
        private static final ThreadLocal contextHolder = new ThreadLocal();
        public static void setCustomerType(String customerType) {
                contextHolder.set(customerType);
        }
        public static String getCustomerType() {
                return contextHolder.get();
        }
        public static void clearCustomerType() {
                contextHolder.remove();
        }
        @Override
        protected Object determineCurrentLookupKey() {
                return getCustomerType();
        }
}



DynamicDataSource.setCustomerType(DynamicDataSource.DATA_SOURCE_MYSQL);






你可能感兴趣的:(数据库)