在web开发中,可以利用hibernate配置数据源,但在实际的应用中,可能要连接多个数据源,
1.配置dataSource
<bean> <property> <value>org.logicalcobwebs.proxool.ProxoolDriver</value> </property> <property> <value>proxool.db</value> </property> </bean>
2.配置sessionFactory
<bean> <property> <ref local="dataSource"></ref> </property> <property> <props> <prop key="hibernate.connection.provider_class"> org.hibernate.connection.C3P0ConnectionProvider</prop> <!-- 是否将运行期生成的SQL输出到日志以供调试 --> <prop key="hibernate.show_sql">true</prop> <!--指定连接的语言--> <prop key="dialect"> org.hibernate.dialect.MySQLDialect </prop> <!--是否收集有助于性能调节的统计数据--> <prop key="hibernate.generate_statistics">true</prop> <!--是否自动重新连接--> <prop key="hibernate.autoReconnect">true</prop> <!--是否自动释放连接--> <prop key="hibernate.connection.release_mode">auto</prop> <!--缓存配置--> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider </prop> <prop key="hibernate.cache.use_second_level_cache"> false </prop> <prop key="hibernate.cache.use_query_cache">false</prop> </props> </property> <property> <list> <value>映射表</value> </list> </property> </bean>
3.添加jdbc支持
<bean> <property> <ref bean="dataSourceLrsql"/> </property> </bean> <bean> <property> <ref bean="jdbcTemplatelr"/> </property> </bean>