<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" 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/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
          

    <!-- 启用CGliB -->
	<aop:aspectj-autoproxy proxy-target-class="true"/>
    
    <!-- base dataSource -->
    <bean name="baseDataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="${druid.initialSize}" />
        <property name="minIdle" value="${druid.minIdle}" />
        <property name="maxActive" value="${druid.maxActive}" />
        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="${druid.maxWait}" />
        <!-- 配置间隔多久才进行一次检测，检测需要关闭的空闲连接，单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="${druid.timeBetweenEvictionRunsMillis}" />
        <!-- 配置一个连接在池中最小生存的时间，单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="${druid.minEvictableIdleTimeMillis}" />
        <property name="validationQuery" value="${druid.validationQuery}" />
        <property name="testWhileIdle" value="${druid.testWhileIdle}" />
        <property name="testOnBorrow" value="${druid.testOnBorrow}" />
        <property name="testOnReturn" value="${druid.testOnReturn}" />
        <!-- 打开PSCache，并且指定每个连接上PSCache的大小 如果用Oracle，则把poolPreparedStatements配置为true，mysql可以配置为false。 -->
        <property name="poolPreparedStatements" value="${druid.poolPreparedStatements}" />
        <property name="maxPoolPreparedStatementPerConnectionSize"
            value="${druid.maxPoolPreparedStatementPerConnectionSize}" />
        <!-- 配置监控统计拦截的filters -->
        <property name="filters" value="${druid.filters}" />
        <!--
         | 加密数据库密码
         | <property name="filters" value="config" />
         | <property name="connectionProperties" value="config.decrypt=true" />
         | -->
    </bean>
    
    <!-- 主库 -->
    <bean id="master-dataSource" name="master-dataSource" parent="baseDataSource" init-method="init" primary="true" >
        <property name="url" value="${jdbc.url}" />
        <!-- <property name="driverClassName" value="com.mysql.jdbc.Driver" />   -->
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>
    
    
    <!--数据源切面注入spring-->
    <bean id="dsChangeAspect" class="com.lyms.aop.DataSourceAspect"/>

    <!--多数据源 -->
	<bean id="dynamicDataSource" class="com.lyms.datasource.DynamicDataSource">
		<property name="defaultTargetDataSource" ref="master-dataSource" />
		<property name="targetDataSources">
			<map key-type="java.lang.String">
				<entry key="master" value-ref="master-dataSource" />
			</map>
		</property>
	</bean>
	<!-- 自定义注入器 -->
	<bean id="deleteLogicByIdSqlInjector" class="com.lyms.mybatis.DeleteLogicByIdSqlInjector" />
	<!-- 注入配置 -->
	<bean id="globalConfig" class="com.baomidou.mybatisplus.entity.GlobalConfiguration">
		<property name="sqlInjector" ref="deleteLogicByIdSqlInjector" />
	</bean>
	
	<bean id="sqlSessionFactory"  class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean">
		<!-- 自定义注入 deleteByIdForYn 方法  -->
		<property name="globalConfig" ref="globalConfig" />
        <property name="dataSource" ref="dynamicDataSource" />
        <property name="plugins">
            <array>
                <bean id="paginationInterceptor"
                    class="com.baomidou.mybatisplus.plugins.PaginationInterceptor">
                    <property name="dialectType" value="mysql" />
                    <!-- <property name="dialectClazz" value="com.baomidou.mybatisplus.plugins.pagination.dialects.MySqlDialect" /> -->
                </bean>
            </array>
        </property>
        <property name="mapperLocations">
            <list>
            	<value>classpath*:com/lyms/cm/dao/*Mapper.xml</value>
                <value>classpath*:com/lyms/cm/dao/*/*Mapper.xml</value>
            </list>
        </property>
        <property name="typeAliasesPackage" value="com.lyms.cm.entity" />
    </bean>
	
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 可以指定多个包名  以逗号或分号分隔 -->
        <property name="basePackage" value="com.lyms.cm.dao" />
        <!-- 标记 -->
        <property name="annotationClass" value="org.springframework.stereotype.Repository" />
    </bean>
</beans>