spring 配置双数据源sql+oracle

oracle配置

	<bean id="dataSource" name="dataSource"
		class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
		<property name="user" value="${jdbc.oracle.user}"></property>
		<property name="password" value="${jdbc.oracle.password}"></property>
		<property name="jdbcUrl" value="${jdbc.oracle.jdbcUrl}"></property>
		<property name="driverClass" value="${jdbc.oracle.driverClass}"></property>
	</bean>
	<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<!-- 空的sqlMap -->
		<property name="configLocation">
			<value>classpath:sql-map-config.xml</value>
		</property>
		<!-- 配置该数据源被那些ibatis使用 -->
		<property name="mappingLocations">
			<value>classpath*:/com/-ibatis2.xml</value>
		</property>
		<property name="dataSource" ref="dataSource" />
		<property name="useTransactionAwareDataSource" value="true"></property>
	</bean>

SQL Server配置

	<bean id="dataSourceMS" name="dataSourceMS"  class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" >
		<property name="user" value="${jdbc.ms.user}"></property>
		<property name="password" value="${jdbc.ms.password}"></property>
		<property name="jdbcUrl" value="${jdbc.ms.jdbcUrl}"></property>
		<property name="driverClass" value="${jdbc.ms.driverClass}"></property>
	</bean>
	<bean id="sqlMapClientMS" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocation">
            <value>classpath:sql-map-config.xml</value>
        </property>
        <property name="mappingLocations">
        	<value>classpath*:/com/-ibatis2.xml</value>
        </property>
        <property name="dataSource" ref="dataSourceMS"/>
        <property name="useTransactionAwareDataSource" value="true"></property>   
    </bean>
    <!-- 指定Dao使用的数据源 -->
 	<bean id="userFilterDao" class="com.sinolife.mas.dao.UserFilterDao"> 
 		<property name="dataSource"><ref bean="dataSourceMS" /></property>
    	<property name="sqlMapClient" ref="sqlMapClientMS"></property>
    </bean>

cfg.properties

jdbc.jdbcUrl=jdbc:oracle:thin:@[IP]:1521:[DBName]
jdbc.driverClass=oracle.jdbc.driver.OracleDriver
jdbc.ms.jdbcUrl=jdbc:sqlserver://[IP]:1433;DatabaseName=[DBName]
jdbc.ms.driverClass=com.microsoft.sqlserver.jdbc.SQLServerDriver



 
<sqlMapConfig>
  	<settings
	    cacheModelsEnabled="false"
	    lazyLoadingEnabled="false"
	    enhancementEnabled="false"
	    maxSessions="1500"
	    maxTransactions="1500"
	    maxRequests="1500"
	    useStatementNamespaces="true"/>
    
    
   	  <sqlMap resource="sqlmap/empty-map.xml"/>
sqlMapConfig>

你可能感兴趣的:(Java)