1. 程式人生 > >spring整合mybatis的配置檔案

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:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
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/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
>
<!--載入配置檔案 --> <context:property-placeholder location="classpath:db.properties" /> <!-- 資料來源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="user" value="${jdbc.username}" /> <property name
="password" value="${jdbc.password}" />
<property name="jdbcUrl" value="${jdbc.url}" /> <property name="driverClass" value="${jdbc.driverClassName}" /> </bean> <!--sqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!--省略sqlmapconfig.xml--> <!--<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property>--> <property name="mapperLocations" value="classpath*:com/zhmhxy/taotao/dao/*.xml"/> <!--另一種寫法--> <!--<property name="mapperLocations" >--> <!--<list>--> <!--<value>classpath*:com/zhmhxy/taotao/dao/*.xml</value>--> <!--</list>--> <!--</property>--> <property name="plugins"> <!--參考:http://blog.csdn.net/estelle_belle/article/details/46356575--> <array> <bean class="com.github.pagehelper.PageHelper"> <!--分頁工具,在sql語句傳送前根據mysql方言拼接limit--> <property name="properties" > <value>dialect=mysql</value> </property> </bean> </array> </property> </bean> <!-- 管理mapper介面 --> <!-- <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface" value="com.zhmhxy.taotao.dao.UserMapper"></property> <property name="sqlSessionFactory" ref="sqlSessionFactory"></property> </bean> --> <!-- 使用mapper掃描管理所有的代理mapper --> <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.zhmhxy.taotao.dao"></property> </bean> </beans>