SSH配置文件 带事务

view plaincopy to clipboardprint?
<?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:tx="http://www.springframework.org/schema/tx
    xmlns:aop="http://www.springframework.org/schema/aop
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd "> 
    <!-- Hibernate的会话 --> 
    <bean id="sessionFactory" 
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" 
        scope="singleton"> 
        <property name="dataSource" ref="dataSource"/> 
        <property name="hibernateProperties"> 
            <props> 
                <prop key="hibernate.dialect"> 
                    org.hibernate.dialect.SQLServerDialect  
                </prop> 
                <prop key="hibernate.show_sql">true</prop> 
                <!-- 设置查询结果集可以回滚,在分页时必须这样 --> 
                <prop key="jdbc.use_scrollable_resultset">true</prop> 
                <prop key="hbm2ddl">true</prop> 
            </props> 
        </property> 
        <property name="mappingResources"> 
            <list> 
                <value>abu/csdn/bean/User.hbm.xml</value> 
            </list> 
        </property> 
    </bean> 
      
    <!-- Spring的Hibernate工具类HibernateTemplate --> 
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" scope="singleton"> 
        <property name="sessionFactory" ref="sessionFactory"/> 
    </bean> 
    <!-- 数据源 --> 
    <bean id="dataSource" 
        class="org.apache.commons.dbcp.BasicDataSource" scope="singleton"> 
        <property name="driverClassName" 
            value="com.microsoft.sqlserver.jdbc.SQLServerDriver"> 
        </property> 
        <property name="url" 
            value="jdbc:sqlserver://localhost:1433;databaseName=csu"> 
        </property> 
        <property name="username" value="liky"/> 
        <property name="password" value="redhat"/> 
    </bean> 
    <!-- Spring的声明式事务 --> 
    <bean id="transactionManager" 
        class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
        <property name="sessionFactory" ref="sessionFactory"/> 
    </bean> 
    <!-- 配置事务的传播特性,通常应该将事务设置在业务层,而非dao上 --> 
    <tx:advice id="txAdvice" transaction-manager="transactionManager"> 
        <tx:attributes> 
            <!-- name为事务对哪些方法生效,可以使用通配符; propagation为事务的传播特性,一共有6种--> 
            <tx:method name="save*" propagation="REQUIRED" /> 
            <tx:method name="delete*" propagation="REQUIRED" /> 
            <tx:method name="update*" propagation="REQUIRED" /> 
            <tx:method name="find*" read-only="true" /> 
        </tx:attributes> 
    </tx:advice> 
    <!-- 切入点,就是哪些包的哪些类的哪些方法参与事务 --> 
    <aop:config> 
        <!-- id是一个标识,expression中的execution表达式比较复杂:  
            1.第一个星号表示匹配所有的返回值;2.abu.csdn.service表示包;3.第二个星号表示匹配这个包的所有类  
            4.第三个星号表示匹配类的所有方法;5.括号内表示方法的参数;6.两个点表示匹配所有的参数   
        --> 
        <aop:pointcut id="allServiceMethods" 
            expression="execution(* abu.csdn.service.*.*(..))" /> 
        <!-- 指定事务和切入点 --> 
        <aop:advisor pointcut-ref="allServiceMethods" 
            advice-ref="txAdvice" /> 
    </aop:config> 
      
</beans> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值