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 xsi:schemaLocation="http://www.springframework.org/schema/beans 6 http://www.springframework.org/schema/beans/spring-beans.xsd 7 http://www.springframework.org/schema/context 8 http://www.springframework.org/schema/context/spring-context.xsd"> 9 <!-- 配置整合mybatis过程 --> 10 <!-- 1.配置数据库相关参数properties的属性:${url} --> 11 <context:property-placeholder location="classpath:jdbc.properties"/> 12 13 <!-- 2.数据库连接池 --> 14 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 15 <!-- 配置连接池属性 --> 16 <property name="driverClass" value="${jdbc.driver}"/> 17 <property name="jdbcUrl" value="${jdbc.url}"/> 18 <property name="user" value="${jdbc.username}"/> 19 <property name="password" value="${jdbc.password}"/> 20 21 <!-- c3p0连接池的私有属性 --> 22 <property name="maxPoolSize" value="30"/> 23 <property name="minPoolSize" value="10"/> 24 <!-- 关闭连接后不自动commit --> 25 <property name="autoCommitOnClose" value="false"/> 26 <!-- 获取连接超时时间 --> 27 <property name="checkoutTimeout" value="10000"/> 28 <!-- 当获取连接失败重试次数 --> 29 <property name="acquireRetryAttempts" value="2"/> 30 </bean> 31 32 <!-- 3.配置SqlSessionFactory对象 --> 33 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 34 <!-- 注入数据库连接池 --> 35 <property name="dataSource" ref="dataSource"/> 36 <!-- 配置MyBaties全局配置文件:mybatis-config.xml --> 37 <property name="configLocation" value="classpath:mybatis-config.xml"/> 38 <!-- 扫描entity包 使用别名 --> 39 <property name="typeAliasesPackage" value="org.ryanjie.entity"/> 40 <!-- 扫描sql配置文件:mapper需要的xml文件 --> 41 <property name="mapperLocations" value="classpath:mapper/*.xml"/> 42 </bean> 43 44 <!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到soring容器中 --> 45 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 46 <!-- 注入sqlSessionFactory --> 47 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> 48 <!-- 给出需要扫描Dao接口包 --> 49 <property name="basePackage" value="com.ryanjie.o2o.dao"/> 50 </bean> 51 52 <!-- RedisDao --> 53 <bean id="redisDao" class="org.seckill.dao.cache.RedisDao"> 54 <constructor-arg index="0" value="localhost" /> 55 <constructor-arg index="1" value="6379" /> 56 </bean> 57 58 </beans>