<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jdbc="http://www.springframework.org/schema/jdbc"
       xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"
       default-lazy-init="true">

    <context:component-scan base-package="com.izouma.awesomeadmin.datasource" />

    <!-- 配置整合mybatis过程 -->
    <!-- 1:配置数据库相关参数 properties 的属性 ： ${url} -->
    <context:property-placeholder ignore-unresolvable="true" location="classpath:properties/jdbc.properties"/>
    <util:properties id="APP_PROP" location="classpath:/properties/jdbc.properties" local-override="true"/>
    <!-- 2：数据库连接池 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <!-- 配置连接池属性 -->
        <property name="driverClass" value="${jdbc.driverClassName}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>

        <!-- c3p0链接池的私有属性 -->
        <property name="maxPoolSize" value="10"/>
        <property name="minPoolSize" value="5"/>
        <!-- 关闭连接hou不自动commit -->
        <property name="autoCommitOnClose" value="false"/>
        <!-- 获取连接超时时间 -->
        <property name="checkoutTimeout" value="10000"/>
        <!-- 当获取链接失败重试次数 -->
        <property name="acquireRetryAttempts" value="2"/>

    </bean>


    <!-- 配置从数据源 -->
    <bean id="dataSourceSlaver" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driverClassName}"/>
        <property name="jdbcUrl" value="${jdbc.slaver.url}"/>
        <property name="user" value="${jdbc.slaver.username}"/>
        <property name="password" value="${jdbc.slaver.password}"/>

        <!-- c3p0链接池的私有属性 -->
        <property name="maxPoolSize" value="10"/>
        <property name="minPoolSize" value="5"/>
        <!-- 关闭连接hou不自动commit -->
        <property name="autoCommitOnClose" value="false"/>
        <!-- 获取连接超时时间 -->
        <property name="checkoutTimeout" value="10000"/>
        <!-- 当获取链接失败重试次数 -->
        <property name="acquireRetryAttempts" value="2"/>
    </bean>


    <!-- 配置从数据源 -->
    <bean id="dataSourceSqlserver" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${sqlserver.driver}"/>
        <property name="jdbcUrl" value="${sqlserver.url}"/>
        <property name="user" value="${sqlserver.user}"/>
        <property name="password" value="${sqlserver.password}"/>

        <!-- c3p0链接池的私有属性 -->
        <property name="maxPoolSize" value="10"/>
        <property name="minPoolSize" value="5"/>
        <!-- 关闭连接hou不自动commit -->
        <property name="autoCommitOnClose" value="false"/>
        <!-- 获取连接超时时间 -->
        <property name="checkoutTimeout" value="10000"/>
        <!-- 当获取链接失败重试次数 -->
        <property name="acquireRetryAttempts" value="2"/>
    </bean>


    <bean id="dynamicDataSource" class="com.izouma.awesomeadmin.datasource.DynamicDataSource">
        <property name="targetDataSources">
            <map key-type="java.lang.String">
                <!-- 指定lookupKey和与之对应的数据源 -->
                <entry key="dataSource" value-ref="dataSource"></entry>
                <entry key="dataSourceSlaver" value-ref="dataSourceSlaver"></entry>
                <entry key="dataSourceSqlserver" value-ref="dataSourceSqlserver"></entry>
            </map>
        </property>
        <!-- 这里可以指定默认的数据源 -->
        <property name="defaultTargetDataSource" ref="dataSource"/>
    </bean>


    <!--<bean id="dataSourceAspect" class="com.izouma.awesomeadmindatasource.DataSourceAspect"></bean>-->
        <!--<aop:config>-->
            <!--<aop:aspect ref="dataSourceAspect">-->
                <!--&lt;!&ndash; 拦截所有service方法 &ndash;&gt;-->
                <!--<aop:pointcut id="dataSourcePointcut" expression="execution(* com.izouma..*(..))"/>-->
                <!--<aop:before pointcut-ref="dataSourcePointcut" method="intercept"/>-->
            <!--</aop:aspect>-->
        <!--</aop:config>-->


    <!--开启aop注解模式-->
    <aop:aspectj-autoproxy/>

    <!--3： 配置 SqlSessionFactory 对象-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dynamicDataSource"/>
        <!-- 配置MyBatis全局配置文件：mybatis-config.xml -->
        <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
        <!-- 扫描entity包 使用别名 -->
        <property name="typeAliasesPackage" value="com.izouma.awesomeadmin.model"/>
        <!-- 扫描sql配置文件：mapper需要的xml文件 -->
        <property name="mapperLocations" value="classpath:com/izouma/awesomeadmin/dao/*Mapper.xml"/>
    </bean>


    <!-- 4： 配置扫描Dao接口包，动态实现Dao接口，注入到Spring容器中-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 注入sqlSessionFactory -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
        <!-- 给出需要扫描dao接口包 -->
        <property name="basePackage" value="com.izouma.awesomeadmin.dao"/>

    </bean>

</beans>