程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> spring入門(14)ssh中事務處理spring配置文件

spring入門(14)ssh中事務處理spring配置文件

編輯:關於JAVA
<?xml version="1.0" encoding="UTF-8"?>    
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" 

xmlns:tx="http://www.springframework.org/schema/tx"
    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/tx    
           http://www.springframework.org/schema/tx/spring-tx.xsd">    
        
    <!-- 數據庫連接的數據源 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">    
        <!-- 數據庫連接驅動 -->
        <property name="driverClassName" value="${jdbc.driverClassName}"  />    
        <!-- 連接的用戶名 -->
        <property name="username" value="${jdbc.username}"  />    
        <!-- 連接的用戶密碼 -->
        <property name="password" value="${jdbc.password}"  />    
        <!-- 連接的url地址 -->
        <property name="url" value="${jdbc.url}"  />    
    </bean>    
        
        
    <!--sessionFactory工廠 -->
    <bean id="localSessionFactoryBean"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">    
        <property name="dataSource" ref="dataSource"  />    
        <property name="mappingResources">    
            <array>    
                <value>www/csdn/spring/demo/domain/Admins.hbm.xml</value>    
                <value>www/csdn/spring/demo/domain/Atusers.hbm.xml</value>    
                <value>www/csdn/spring/demo/domain/Collctions.hbm.xml</value>    
                <value>www/csdn/spring/demo/domain/Comments.hbm.xml</value>    
                <value>www/csdn/spring/demo/domain/Messages.hbm.xml</value>    
                <value>www/csdn/spring/demo/domain/Pictures.hbm.xml</value>    
                <value>www/csdn/spring/demo/domain/PrivateLetter.hbm.xml</value>    
                <value>www/csdn/spring/demo/domain/Relation.hbm.xml</value>    
                <value>www/csdn/spring/demo/domain/UserInfo.hbm.xml</value>    
                <value>www/csdn/spring/demo/domain/Users.hbm.xml</value>    
            </array>    
        </property>    
        <property name="hibernateProperties">    
            <props>    
                <prop key="hibernate.show_sql">true</prop>    
                <prop 

key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory    
                </prop>    
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>    
            </props>    
        </property>    
    </bean>    
        
    <!-- 配置HibernateTemplate -->
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">    
        <property name="sessionFactory" ref="localSessionFactoryBean"  />    
    </bean>    
    <!-- 實現hibernateDaoSupport抽象接口來使用 -->
    <bean id="hibernateDaoSupport"
        class="org.springframework.orm.hibernate3.support.HibernateDaoSupport"
        abstract="true">    
        <property name="hibernateTemplate" ref="hibernateTemplate"  />    
    </bean>    
        
    <!-- 創建hibernate事務管理器 -->
    <bean id="hibernateTransactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">    
        <property name="sessionFactory" ref="localSessionFactoryBean"  />    
    </bean>    
    <!-- 事務的通知 -->
    <tx:advice id="txAdvice" transaction-manager="hibernateTransactionManager">    
        <!-- 事務的屬性 -->
        <tx:attributes>    
            <!-- 事務的具體執行方法 -->
            <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"  />    
            <tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT"  />    
            <tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT"
                read-only="true"  />    
        </tx:attributes>    
    </tx:advice>    
    <!-- 切面 -->
    <aop:config>    
        <aop:pointcut expression="execution(* *..service.*.*(..))"
            id="mycut"  />    
        <aop:advisor advice-ref="txAdvice" pointcut-ref="mycut"  />    
    </aop:config>    
        
</beans>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved