spring-dao.xml 3.09 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:context="http://www.springframework.org/schema/context"
	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/context 
     		http://www.springframework.org/schema/context/spring-context.xsd
     		http://www.springframework.org/schema/aop
    		http://www.springframework.org/schema/aop/spring-aop.xsd"
	default-autowire="byName">

	<context:component-scan base-package="com.b2c.orders.dao" />

	<bean id="masterDataSource" class="com.alibaba.druid.pool.DruidDataSource"
		init-method="init" destroy-method="close">
		<property name="driverClassName" value="${jdbc.driverClass}" />
		<property name="url" value="${jdbc.jdbcUrl}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<!-- 添加监控,SQL注入防火墙 -->
		<property name="filters" value="stat,logback" />
		<!-- 慢查询 -->
		<property name="connectionProperties" value="druid.stat.slowSqlMillis=1000" />
		<property name="maxActive" value="100" />
		<property name="initialSize" value="1" />
		<property name="maxWait" value="60000" />
		<property name="minIdle" value="1" />
		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="60000" />
		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="300000" />
		<property name="validationQuery" value="SELECT now()" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />
		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
		<property name="poolPreparedStatements" value="true" />
		<property name="maxOpenPreparedStatements" value="20" />

		<!-- 超过时间限制是否回收 -->
		<property name="removeAbandoned" value="true" />
		<!-- 超时时间;单位为秒。180秒=3分钟 -->
		<property name="removeAbandonedTimeout" value="180" />
		<!-- 关闭abanded连接时输出错误日志 -->
		<property name="logAbandoned" value="true" />

		<!-- 配置公用监控数据 -->
		<property name="useGlobalDataSourceStat" value="true" />
	</bean>

	<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="masterDataSource" />
	</bean>

	<!-- 集成Mybatis -->
	<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="masterDataSource" />
		<property name="configLocation" value="classpath:sqlmap-config.xml" />
	</bean>
	<bean id="sqlTemplate" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg index="0" ref="sessionFactory" />
	</bean>
	
</beans>