spring-dao.xml 模板

 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>
相關文章
相關標籤/搜索