spring整合mybatis配置文件

<?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">
	<!-- 开启自动扫描 -->
	<context:component-scan base-package="com.project.spring_mybatis"></context:component-scan>
	<!-- -->
	<aop:aspectj-autoproxy />
	<!-- 引入外部数据库的配置文件,location位置填写的是相对位置 -->
	<context:property-placeholder location="jdbc.properties"
		ignore-resource-not-found="false" local-override="false" />
	<!-- 配置数据库连接池 -->
	<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
		<property name="driverClassName" value="${jdbc.driver}"></property>
		<property name="url" value="${jdbc.url}"></property>
		<property name="username" value="${jdbc.username}"></property>
		<property name="password" value="${jdbc.password}"></property>
		<!-- 是否默认自动提交 -->
		<property name="defaultAutoCommit" value="false"></property>
		<!-- 是否为只读 -->
		<property name="defaultReadOnly" value="false"></property>
		<!-- 默认的事务隔离级别 -->
		<property name="defaultTransactionIsolation" value="4" />


		<!-- dbcp在初始化时,新建的连接数量 -->
		<property name="initialSize" value="10" />
		<!-- 在同一时间能够拥有最大的活跃的连接的数量 -->
		<property name="maxTotal" value="50" />
		<!-- 配置空闲区的最小连接数 -->
		<property name="minIdle" value="0" />
		<!-- 配置空闲区的最大连接数 -->
		<property name="maxIdle" value="10" />


		<!-- 设置连接处理查询语句的超时时间,单位为秒 -->
		<property name="validationQueryTimeout" value="10"></property>
		<!-- 连接池中是否允许缓存预编译对象 -->
		<property name="poolPreparedStatements" value="true" />
	</bean>


	<!-- ========================================针对myBatis的配置项============================== -->
	<!-- 配置SessionFactory -->
	<bean name="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 实例化sqlSessionFactory时需要使用上述配置好的数据源以及SQL映射文件 -->
		<property name="dataSource" ref="dataSource" />
		<property name="typeAliasesPackage" value="com.project.spring_mybatis.beans"></property>
		<property name="mapperLocations" value="com.project.spring_mybatis.stumag.mapper.*" />
	</bean>
	<!-- 扫描mapper配置文件的地址 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.project.spring_mybatis.stumag.mapper.*" />
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
	</bean>
	<!-- 配置Spring的事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

</beans>

猜你喜欢

转载自blog.csdn.net/hlp4207/article/details/79438135