spring-dao.xml 模板
阿新 • • 發佈:2018-12-19
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/beans6 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-placeholderlocation="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>