spring+springMVC+mybatis+shiro -- spring-mybatis.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- @author ForeignStudent @version 2017/9/20 -->
<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"
    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">

    <!-- 这里可以不用扫描properties配置文件,但是为了以后可以把配置文件分开,所以加上,这里扫描的是同一个 -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:applicationContext/spring.properties</value>
            </list>
        </property>
    </bean>

    <!-- 数据源 -->
    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${sql_member_driver}" />
        <property name="url" value="${sql_member_url}" />
        <property name="username" value="${sql_member_username}" />
        <property name="password" value="${sql_member_password}" />
        <property name="initialSize" value="${sql_member_initalSize}" />
        <property name="maxTotal" value="${sql_member_maxTotal}" />
        <property name="maxIdle" value="${sql_member_maxIdle}" />
        <property name="minIdle" value="${sql_member_minIdle}" />
        <property name="maxWaitMillis" value="${sql_member_maxWaitMillis}" />
    </bean>

    <!-- spring和MyBatis整合 -->
    <bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="mapperLocations" value="classpath*:com/conferencerooms/mapperXml/*Mapper.xml" />
        <property name="typeAliasesPackage" value="com.conferencerooms.entity" />
        <property name="plugins">
            <array>
                <!-- 分页插件配置 -->
                <bean id="paginationInterceptor" class="com.baomidou.mybatisplus.plugins.PaginationInterceptor">
                    <property name="dialectType" value="mysql" />
                </bean>
            </array>
        </property>
        <!-- 全局配置注入 -->
        <property name="globalConfig" ref="globalConfig" />
    </bean>
    
    <bean id="globalConfig" class="com.baomidou.mybatisplus.entity.GlobalConfiguration">
        <!-- 
            AUTO->`0`("数据库ID自增")
             INPUT->`1`(用户输入ID")
            ID_WORKER->`2`("全局唯一ID")
            UUID->`3`("全局唯一ID")
        -->
        <property name="idType" value="3" />
        <!--
            MYSQL->`mysql`
            ORACLE->`oracle`
            DB2->`db2`
            H2->`h2`
            HSQL->`hsql`
            SQLITE->`sqlite`
            POSTGRE->`postgresql`
            SQLSERVER2005->`sqlserver2005`
            SQLSERVER->`sqlserver`
        -->
        <!-- Oracle需要添加该项 -->
        <!-- <property name="dbType" value="oracle" /> -->
        <!-- 全局表为下划线命名设置 true -->
        <property name="dbColumnUnderline" value="true" />
    </bean>

    <!-- MyBatis 动态实现 -->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 对Dao 接口动态实现,需要知道接口在哪 -->
        <property name="basePackage" value="com.conferencerooms.mapper" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>

    <!-- 事务管理 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- 事务注解 -->
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
    <!-- 事务管理 属性 -->
    <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="select*" propagation="REQUIRED" read-only="true" />
            <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception" />
            <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception" />
            <tx:method name="insert*" propagation="REQUIRED" rollback-for="Exception" />
            <tx:method name="*" propagation="REQUIRED" />
        </tx:attributes>
    </tx:advice>

    <!-- 配置切面 -->
    <aop:config expose-proxy="true" proxy-target-class="true">
        <aop:advisor advice-ref="transactionAdvice" pointcut="execution(* com.conferencerooms.service..*.*(..))" />
    </aop:config>
</beans>
原文地址:https://www.cnblogs.com/foreign-student/p/7594053.html