(编辑:jimmy 日期: 2024/11/11 浏览:2)
在web开发中,可以利用hibernate配置数据源,但在实际的应用中,可能要连接多个数据源,
1.配置dataSource
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>org.logicalcobwebs.proxool.ProxoolDriver</value> </property> <property name="url"> <value>proxool.db</value> </property> </bean>
2.配置sessionFactory
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="dataSource"></ref> </property> <property name="hibernateProperties"> <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 name="mappingResources"> <list> <value>映射表</value> </list> </property> </bean>
3.添加jdbc支持
<bean id="jdbcTemplatelr" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource"> <ref bean="dataSourceLrsql"/> </property> </bean> <bean id="basePageDao" class="com.BasePageDaoHibernateImpl"> <property name="jdbcTemplate"> <ref bean="jdbcTemplatelr"/> </property> </bean>
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!