当前位置:首页 > 开发 > 系统架构 > 架构 > 正文

spring中datasource配置

发表于: 2011-10-11   作者:g21121   来源:转载   浏览:
摘要: datasource配置有很多种,我介绍的一种是采用c3p0的,它的百科地址是: http://baike.baidu.com/view/920062.htm   <!-- spring加载资源文件 --> <bean name="propertiesConfig" class="org.springframework.b

datasource配置有很多种,我介绍的一种是采用c3p0的,它的百科地址是:

http://baike.baidu.com/view/920062.htm

 

	<!-- spring加载资源文件 -->
	<bean name="propertiesConfig"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:jdbc.properties</value>
							</list>
		</property>
	</bean>
	<!-- 数据源配置 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${datasource.driverClassName}" />
		<property name="jdbcUrl" value="${datasource.url}" />
		<property name="user" value="${datasource.user}" />
		<property name="password" value="${datasource.password}" />
		<property name="minPoolSize" value="${datasource.minPoolSize}" />
		<property name="maxPoolSize" value="${datasource.maxPoolSize}" />
		<property name="maxIdleTime" value="${datasource.maxIdleTime}" />
		<property name="acquireIncrement" value="${datasource.acquireIncrement}" />
		<property name="maxStatements" value="${datasource.maxStatements}" />
		<property name="initialPoolSize" value="${datasource.initialPoolSize}" />
		<property name="idleConnectionTestPeriod" value="${datasource.idleConnectionTestPeriod}" />
		<property name="acquireRetryAttempts" value="${datasource.acquireRetryAttempts}" />
		<property name="breakAfterAcquireFailure" value="${datasource.breakAfterAcquireFailure}" />
		<property name="testConnectionOnCheckout" value="${datasource.testConnectionOnCheckout}" />
	</bean>

 下面是jdbc.properties的配置:

#datasource.driverClass=oracle.jdbc.driver.OracleDriver
datasource.driverClassName=com.mysql.jdbc.Driver
datasource.url=jdbc\:mysql\://192.168.1.1\:3306/xxx
datasource.user=root
datasource.password=123456
#Optional
datasource.minPoolSize=1
datasource.maxPoolSize=50
datasource.maxIdleTime=25000
datasource.acquireIncrement=2
datasource.maxStatements=0
datasource.initialPoolSize=2
datasource.idleConnectionTestPeriod=25000
datasource.acquireRetryAttempts=30
datasource.breakAfterAcquireFailure=true
datasource.testConnectionOnCheckout=true

 

spring中datasource配置

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号