【Java Web】【6】SSM spring+struts+mybatis整合(三)数据源配置

1.    数据源配置在spring-datasource.xml中

<?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:jdbc="http://www.springframework.org/schema/jdbc" 
	xmlns:context="http://www.springframework.org/schema/context" 
	xsi:schemaLocation="      
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd      
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd      
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd      
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">  
	<!-- erp系统数据源配置 -->
   	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="${jdbc.driverClassName}"/>
		<property name="url" value="${jdbc.url}"/>
		<property name="username" value="${jdbc.username}"/>
		<property name="password" value="${jdbc.password}"/>
		<property name="maxActive" value="15" />
		<property name="maxIdle" value="10" />
		<property name="maxWait" value="1000" />
		<!--removeAbandoned: 是否自动回收超时连接-->  
		<property name="removeAbandoned" value="true"/>  
		<!--removeAbandonedTimeout: 超时时间(以秒数为单位)-->  
		<property name="removeAbandonedTimeout" value="300"/>  
		<property name="validationQuery">  
		   <value>SELECT * from DUAL</value>  
		</property>  
	</bean>
	<!-- 配置sqlSessionFactory -->  
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource" />  
        <property name="configLocation" value="classpath:mybatis.xml" /> 
        <property name="mapperLocations" value="classpath*:mybatis-conf/*.xml"></property>
    </bean>
    <!-- 配置sqlSessionTemplate -->  
    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">  
        <constructor-arg index="0" ref="sqlSessionFactory" />  
    </bean>
    <!-- 配置事务 -->  
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource" />  
    </bean>
    <tx:annotation-driven transaction-manager="txManager" />
	<!-- erp系统数据源配置结束 -->
</beans>

PS:数据源配置在spring中,在项目中的位置

猜你喜欢

转载自blog.csdn.net/liangayang/article/details/80648782
今日推荐