读书人

Spring 配备多个数据源

发布时间: 2012-06-28 15:20:03 作者: rapoo

Spring 配置多个数据源
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd">

<!--*************************************************************************************************************************-->
<!-- 定义数据源Bean,使用C3P0数据源实现 -->
<bean id="dataSource" destroy-method="close">
<!-- 指定连接数据库的驱动 -->
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<!-- 指定连接数据库的URL -->
<property name="jdbcUrl" value="jdbc:mysql://localhost/a0121"/>
<!-- 指定连接数据库的用户名 -->
<property name="user" value="a"/>
<!-- 指定连接数据库的密码 -->
<property name="password" value="a"/>
<!-- 指定连接数据库连接池的最大连接数 -->
<property name="maxPoolSize" value="20"/>
<!-- 指定连接数据库连接池的最小连接数 -->
<property name="minPoolSize" value="1"/>
<!-- 指定连接数据库连接池的初始化连接数 -->
<property name="initialPoolSize" value="1"/>
<!-- 指定连接数据库连接池的连接的最大空闲时间 -->
<property name="maxIdleTime" value="20"/>
</bean>

<!--定义了Hibernate的SessionFactory -->
<bean id="sessionFactory" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>/hibernate-map-xml/AripBaseinfoOrg.hbm.xml</value>
<value>/hibernate-map-xml/Tlorrybaseinfo.hbm.xml</value>
<value>/hibernate-map-xml/Tlorrypp.hbm.xml</value>
<value>/hibernate-map-xml/Tlorrysjinfo.hbm.xml</value>
<value>/hibernate-map-xml/Tlorrystate.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
</props>
</property>
</bean>

<bean id="transactionManager" ref="sessionFactory"/>
</bean>


<bean id="transactionInterceptor" ref="transactionManager"/>
<property name="transactionAttributes">
<!-- 下面定义事务传播属性-->
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<!--******************************************************************************************************************************-->
<!-- 定义连接 GPS 服务器数据库 -->
<bean id="dataSourceGPS" destroy-method="close">
<property name="driverClass" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
<property name="jdbcUrl" value="jdbc:microsoft:sqlserver://111.225.0.21:1433"/>
<property name="user" value="wt"/>
<property name="password" value="w13"/>
<property name="maxPoolSize" value="20"/>
<property name="minPoolSize" value="1"/>
<property name="initialPoolSize" value="1"/>
<property name="maxIdleTime" value="20"/>
</bean>

<!--定义了Hibernate的SessionFactoryGPS -->
<bean id="sessionFactoryGPS" ref="dataSourceGPS"/>
<property name="mappingResources">
<list>
<value>/hibernate-map-xml/CarGjall.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
</props>
</property>
</bean>

<bean id="transactionManagerGPS" ref="sessionFactoryGPS"/>
</bean>


<bean id="transactionInterceptorGPS" ref="transactionManagerGPS"/>
<property name="transactionAttributes">
<!-- 下面定义事务传播属性-->
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<!--车辆管理******************************************************************************************************************************-->

<!-- 定义了 DAO dtbi dao tlorrybaseinfo imp -->
<bean id="dtbi" ref="sessionFactory"/>
</bean>
<!-- 定义了 DAO b_istate 通过id获取状态 ,比如: 机构代码 车辆品牌代码 车辆使用状态 代码 -->
<bean id="b_istate" ref="sessionFactory"/>
</bean>
<!-- 定义 公共 分页 程序*********************************************************************************************************-->
<bean id="pagerService" ref="sessionFactoryGPS" />
</bean>

<!-- 司机管理 -->
<bean id="dtsi" ref="sessionFactory"/>
</bean>


</beans>

读书人网 >开源软件

热点推荐