spring-dao.xml 3.95 KB
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
	default-autowire="byName">

	<!--<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource"-->
		<!--destroy-method="close">-->
		<!--<property name="driverClass" value="${bonecp.driverClass}" />-->
		<!--<property name="jdbcUrl" value="${bonecp.jdbcUrl}" />-->
		<!--<property name="username" value="${bonecp.username}" />-->
		<!--<property name="password" value="${bonecp.password}" />-->
		<!--<property name="idleConnectionTestPeriodInMinutes" value="${bonecp.idleConnectionTestPeriodInMinutes}" />-->
		<!--<property name="idleMaxAgeInMinutes" value="${bonecp.idleMaxAgeInMinutes}" />-->
		<!--<property name="partitionCount" value="${bonecp.partitionCount}" />-->
		<!--<property name="maxConnectionsPerPartition" value="${bonecp.maxConnectionsPerPartition}" />-->
		<!--<property name="minConnectionsPerPartition" value="${bonecp.minConnectionsPerPartition}" />-->
		<!--<property name="acquireIncrement" value="${bonecp.acquireIncrement}" />-->
		<!--<property name="statementsCacheSize" value="${bonecp.statementsCacheSize}" />-->
		<!--<property name="releaseHelperThreads" value="${bonecp.releaseHelperThreads}" />-->
		<!--<property name="connectionTestStatement" value="select 1" />-->
	<!--</bean>-->

	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
		<!-- 基本属性 url、user、password -->
		<property name="driverClassName" value="${druid.datasource.jdbc.driver}" />
		<property name="url" value="${druid.datasource.jdbc.url}" />
		<property name="username" value="${druid.datasource.jdbc.user}" />
		<property name="password" value="${druid.datasource.jdbc.password}" />

		<!-- 配置初始化大小、最小、最大 -->
		<property name="initialSize" value="${druid.datasource.init.initial.size}" />
		<property name="minIdle" value="${druid.datasource.init.min.idle}" />
		<property name="maxActive" value="${druid.datasource.init.max.active}" />

		<!-- 配置获取连接等待超时的时间 -->
		<property name="maxWait" value="${druid.datasource.max.wait}" />

		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="${druid.datasource.time.between.millis}" />

		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="${druid.datasource.min.idle.time}" />

		<property name="validationQuery" value="SELECT 'x'" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />

		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
		<property name="poolPreparedStatements" value="true" />
		<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />

		<!-- 配置监控统计拦截的filters -->
		<property name="filters" value="stat" />
	</bean>

	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<tx:annotation-driven transaction-manager="transactionManager" />

	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="configLocation" value="classpath:/mybatis/mybatis.cfg.xml"></property>
		<property name="dataSource" ref="dataSource" />
	</bean>

	<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg index="0" ref="sqlSessionFactory" />
	</bean>
</beans>