zoukankan      html  css  js  c++  java
  • ssm整合

    <?xml version="1.0" encoding="UTF-8"?>                    
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:c="http://www.springframework.org/schema/c"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        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/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd
            ">
        <!-- 第一部分:开启注解扫描 context标签 -->
        <context:component-scan base-package="com.bw"></context:component-scan>
        <!-- 加载外部资源文件 -->
        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:database.properties</value>
                </list>
            </property>
        </bean> 
            
            
        <!-- 第二部分  配置数据源 -->        
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="${driver}"></property>
            <property name="url" value="${url}"></property>
            <property name="username" value="${use}"></property>
            <property name="password" value="${pass}"></property>
        </bean>
        <!--第三部分 配置sqlSessionfactorybean对象  -->
        <bean  id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!--         <property name="configLocation" value="classpath:mybatis_config.xml"></property>
     -->        
            <property name="dataSource" ref="dataSource"></property>
            <property name="typeAliasesPackage" value="com.bw.pojo"></property>
            <property name="mapperLocations" value="com/bw/mapper/*.xml"/>
        </bean>
        
        <!-- 第四部分  配置MapperFactoryBean -->
        <!-- 配置mapper的批量扫描接口生成实例对象 -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <!--  配置扫描mapper的包路径-->
            <property name="basePackage" value="com.bw.mapper"></property>
    <!--         <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
     -->    </bean>
        
        <!--  配置注解的事务管理
        <tx:annotation-driven transaction-manager="transactionManager"/>-->
        
            <!-- 第五部分 配置事务的管理  -->
         <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"></property>
        </bean>
        <!--  第六部分   事务的通知 -->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <!-- 
                propagation 传播特性 7个  默认是有事务操作的  
                 isolation隔离级别 4中   默认跟数据库的级别一致
                 spring:只捕获RuntimeException  才会回滚
                  -->
                <tx:method name="insert*" propagation="REQUIRED" isolation="DEFAULT" rollback-for="java.lang.Exception"/>
                <tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT"/>
                <tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT"/>
                <tx:method name="get*" propagation="NOT_SUPPORTED" isolation="DEFAULT"/>
                <tx:method name="select*" propagation="NOT_SUPPORTED" isolation="DEFAULT"/>
            </tx:attributes>
        </tx:advice>
        
        <!-- 第七部分  使用aop 配置事务的通知   
            事务分两种
            声明式  1.Aop的事务管理  2. 注解的事务管理
            编程式的事务管理
            spring:只捕获RuntimeException,才会回滚
         -->
        <aop:config >
            <!--配置 切入点 -->
            <aop:pointcut expression="execution(* com.bw.service.*.*(..))" id="pc"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="pc"/>
        </aop:config> 
    </beans>

  • 相关阅读:
    HDU 2196 Computer
    HDU 1520 Anniversary party
    POJ 1217 FOUR QUARTERS
    POJ 2184 Cow Exhibition
    HDU 2639 Bone Collector II
    POJ 3181 Dollar Dayz
    POJ 1787 Charlie's Change
    POJ 2063 Investment
    HDU 1114 Piggy-Bank
    Lca hdu 2874 Connections between cities
  • 原文地址:https://www.cnblogs.com/JBLi/p/10513057.html
Copyright © 2011-2022 走看看