<?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:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

    <!-- 定义Mybatis的SqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 定义数据源 -->
        <property name="dataSource" ref="${dataSource}"/>
        <property name="databaseIdProvider" ref="databaseIdProvider"/>
        <!-- 指定mybatis全局配置文件 -->
        <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
        <!-- 扫描mappers目录以及子目录下的所有xml文件 -->
        <property name="mapperLocations" value="classpath:mybatis/mappers/**/*.xml"/>
        <!-- 别名扫描包 -->
        <property name="typeAliasesPackage" value="com.pqs9200.pojo,com.njcn.sso.pojo,com.njcn.pojo"/>
    </bean>

    <bean id="transactionManagerManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="${dataSource}"/>
    </bean>

    <!-- 定义Mapper接口扫描器 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.pqs9200.mapper,com.njcn.mapper"/>
    </bean>

    <!--配置通用mapper -->
    <bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.pqs9200.mapper,com.njcn.mapper"/>
        <property name="properties">
            <value>
                mappers=tk.mybatis.mapper.common.Mapper
                <!-- 仅对insert有效 -->
                ORDER=BEFORE
            </value>
        </property>
    </bean>

</beans>
