spring-mybatis.xml 8.9 KB
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-3.2.xsd">

    <!--&lt;!&ndash; mybatis文件配置,扫描所有mapper文件 &ndash;&gt;-->
    <!--<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"-->
          <!--p:dataSource-ref="dynamicDataSource" p:configLocation="classpath:mybatis-config.xml"-->
          <!--p:mapperLocations="classpath:mapper/*.xml"/>&lt;!&ndash; configLocation为mybatis属性-->
		<!--mapperLocations为所有mapper &ndash;&gt;-->

    <!--&lt;!&ndash; spring与mybatis整合配置,扫描所有dao &ndash;&gt;-->
    <!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"-->
          <!--p:basePackage="com.sibu.orderHelper.base.dao" p:sqlSessionFactoryBeanName="sqlSessionFactory"/>-->
    <!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"-->
          <!--p:basePackage="com.sibu.orderHelper.integral.dao" p:sqlSessionFactoryBeanName="sqlSessionFactory"/>-->
    <!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"-->
          <!--p:basePackage="com.sibu.orderHelper.hotel.dao" p:sqlSessionFactoryBeanName="sqlSessionFactory"/>-->

    <!--&lt;!&ndash; 对数据源进行事务管理 &ndash;&gt;-->
    <!--<bean id="transactionManager"-->
          <!--class="org.springframework.jdbc.datasource.DataSourceTransactionManager"-->
          <!--p:dataSource-ref="dynamicDataSource"/>-->

    <!--&lt;!&ndash; 事务注解驱动,标注@Transactional的类和方法将具有事务性 &ndash;&gt;-->
    <!--<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" mode="proxy"/>-->



    <!-- begin 新系统mall -->
    <bean id="mallReadDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <!-- 基本属性 url、user、password -->
        <property name="url" value="${mall.read.url}?characterEncoding=utf8&amp;zeroDateTimeBehavior=convertToNull&amp;allowMultiQueries=true" />
        <property name="username" value="${mall.read.username}" />
        <property name="password" value="${mall.read.password}" />

        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="1"/>
        <property name="minIdle" value="1"/>
        <property name="maxActive" value="200"/>

        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="60000"/>

        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>

        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="300000"/>

        <property name="validationQuery" value="SELECT 'x'"/>
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>

        <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
        <property name="poolPreparedStatements" value="true"/>
        <property name="maxPoolPreparedStatementPerConnectionSize" value="20"/>

        <!-- 配置监控统计拦截的filters -->
        <property name="filters" value="stat"/>
    </bean>

    <bean id="mallReadSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="mapperLocations" value="classpath:mall-mapper/**/read/**/*.xml" />
        <!--<property name="typeAliasesPackage" value="com.ejavashop.entity" />-->
        <property name="configLocation" value="classpath:mybatis-config.xml"></property>
        <property name="dataSource" ref="mallReadDataSource"/>
    </bean>
    <bean name="mallReadMapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.sibu.orderHelper.mall.*.read" />
        <property name="sqlSessionFactoryBeanName" value="mallReadSqlSessionFactory" />
    </bean>



    <bean id="mallWriteDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <!-- 基本属性 url、user、password -->
        <property name="url" value="${mall.write.url}?characterEncoding=utf8&amp;zeroDateTimeBehavior=convertToNull&amp;allowMultiQueries=true" />
        <property name="username" value="${mall.write.username}" />
        <property name="password" value="${mall.write.password}" />

        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="1"/>
        <property name="minIdle" value="1"/>
        <property name="maxActive" value="200"/>

        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="60000"/>

        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>

        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="300000"/>

        <property name="validationQuery" value="SELECT 'x'"/>
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>

        <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
        <property name="poolPreparedStatements" value="true"/>
        <property name="maxPoolPreparedStatementPerConnectionSize" value="20"/>

        <!-- 配置监控统计拦截的filters -->
        <property name="filters" value="stat"/>
    </bean>

    <bean id="mallWriteSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="mapperLocations" value="classpath:mall-mapper/**/write/**/*.xml" />
        <!--<property name="typeAliasesPackage" value="com.ejavashop.entity" />-->
        <property name="configLocation" value="classpath:mybatis-config.xml"></property>
        <property name="dataSource" ref="mallWriteDataSource" />
    </bean>

    <bean name="shopMapperScannerWrite" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.sibu.orderHelper.mall.*.write" />
        <property name="sqlSessionFactoryBeanName" value="mallWriteSqlSessionFactory" />
    </bean>

    <bean id="transactionManagerForMall" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="mallWriteDataSource"/>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManagerForMall"/>

    <!-- end 新系统mall -->



    <!-- 配置事务的传播特性  -->
    <!--<tx:advice id="txAdvice" transaction-manager="transactionManager">-->
        <!--<tx:attributes>-->
            <!--<tx:method name="*" isolation="DEFAULT" rollback-for="java.lang.Exception" read-only="false" timeout="-1"-->
                       <!--propagation="NEVER"/>-->
        <!--</tx:attributes>-->
    <!--</tx:advice>-->
    <!-- <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="add*" propagation="REQUIRED" read-only="false"
                rollback-for="Exception" />
            <tx:method name="delete*" propagation="REQUIRED" read-only="false"
                rollback-for="Exception" />
            <tx:method name="edit*" propagation="REQUIRED" read-only="false"
                rollback-for="Exception" />
            <tx:method name="proc*" propagation="REQUIRED" read-only="false"
                rollback-for="Exception" />
            <tx:method name="list*" read-only="true"/>
            <tx:method name="*" read-only="false" pro/>
        </tx:attributes>
    </tx:advice> -->
    <!-- 那些类的哪些方法参与事务 -->
    <!-- <aop:config>
        <aop:pointcut id="allManagerMethod" expression="execution(* com.sibu.orderHelper.integral.service.*.*(..))" />
        <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice" />
    </aop:config> -->
</beans>