1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:tx="http://www.springframework.org/schema/tx" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 7 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 8 9 <!-- 加载mysql数据配置文件 --> 10 <context:property-placeholder location="classpath:database.properties"/> 11 12 <!-- 配置datasource数据源对象 --> 13 <bean id="dataSource" class="com.mchange.v2.c3p0.mbean.C3P0PooledDataSource"> 14 <property name="driverClass" value="${jdbc.driver}" /> 15 <property name="jdbcUrl" value="${jdbc.url}" /> 16 <property name="user" value="${jdbc.username}" /> 17 <property name="password" value="${jdbc.password}" /> 18 <!-- c3p0数据源的私有属性 --> 19 <property name="maxPoolSize" value="30" /> 20 <property name="minPoolSize" value="30" /> 21 <!-- 关闭连接后,不自动提交 --> 22 <property name="autoCommitOnClose" value="false"/> 23 <!-- 获取连接超时时间 --> 24 <property name="checkoutTimeout" value="10000" /> 25 <!-- 获取连接失败,重试次数 --> 26 <property name="acquireIncrement" value="2" /> 27 </bean> 28 29 <!-- 配置sqlSessionFactory对象 --> 30 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 31 <!-- 注入数据库连接池 ,这里为什么是ref?因为dataSource需要的是一个对象--> 32 <property name="dataSource" ref="dataSource" /> 33 <!-- 扫描entity包,使用别名(实体类所在的包) --> 34 <property name="typeAliasesPackage" value="com.imooc.o2o.entity" /> 35 <!-- 配置mybatis全局配置文件:mybatis-config.xml --> 36 <property name="configLocation" value="classpath:mybatis-config.xml" /> 37 <!-- 扫描sql配置文件:mapper需要的xml文件 --> 38 <property name="mapperLocations" value="classpath:mapper/*.xml" /> 39 </bean> 40 41 <!-- 配置扫描DAO接口所在的包,动态实现DAO接口,注入到spring容器中 --> 42 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" > 43 <!-- 注入sqlSessionFactory对象,这里为什么是value?因为sqlSessionFactoryBeanName需要的是一个字符串String --> 44 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> 45 <property name="basePackage" value="classpath:com.imooc.o2o.dao" /> 46 </bean> 47 </beans>
Spring之DAO层配置文件
猜你喜欢
转载自www.cnblogs.com/in-the-game-of-thrones/p/11205327.html
今日推荐
周排行