81,090
社区成员
发帖
与我相关
我的任务
分享
<!-- DataSource -->
<bean id="dataSource_master" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="${dataBase.url}" />
<property name="properties">
<props>
<prop key="c3p0.minPoolSize">1</prop>
<prop key="c3p0.maxPoolSize">60</prop>
<prop key="c3p0.timeout">60</prop>
<prop key="c3p0.max_statement">80</prop>
<prop key="c3p0.testConnectionOnCheckout">true</prop>
<prop key="hibernate.c3p0.testConnectionOnCheckout">false</prop>
<prop key="user">sm_admin</prop>
<prop key="password">sm_admin</prop>
</props>
</property>
</bean>
<bean id="dataSource_one" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass"
value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl"
value="jdbc:oracle:thin:@192.168.1.100:1521:AREAA" />
<property name="properties">
<props>
<prop key="c3p0.minPoolSize">1</prop>
<prop key="c3p0.maxPoolSize">60</prop>
<prop key="c3p0.timeout">60</prop>
<prop key="c3p0.max_statement">80</prop>
<prop key="c3p0.testConnectionOnCheckout">true</prop>
<prop key="hibernate.c3p0.testConnectionOnCheckout">false</prop>
<prop key="user">sm_a_admin</prop>
<prop key="password">sm_admin</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="com.xxxx.xx.service.database.DynamicDataSource">
<property name="targetDataSources">
<map>
<entry key="dataSource_master" value-ref="dataSource_master" />
<entry key="dataSource_one" value-ref="dataSource_one" />
</map>
</property>
<property name="defaultTargetDataSource" ref="dataSource_master" />
</bean>
package com.xxxx.xx.service.database;
import java.sql.SQLException;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
/**
* 动态数据源切换类
*/
public class DynamicDataSource extends AbstractRoutingDataSource {
protected Object determineCurrentLookupKey() {
return DatabaseContextHolder.getDatabaseType();
}
@SuppressWarnings("unchecked")
public boolean isWrapperFor(Class arg0) throws SQLException {
return false;
}
@SuppressWarnings("unchecked")
public Object unwrap(Class arg0) throws SQLException {
return null;
}
}