首页 > Java开发 > ssh事务处理spring配置文件

ssh事务处理spring配置文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans
  6.            http://www.springframework.org/schema/beans/spring-beans.xsd
  7.            http://www.springframework.org/schema/aop
  8.            http://www.springframework.org/schema/aop/spring-aop.xsd
  9.            http://www.springframework.org/schema/tx
  10.            http://www.springframework.org/schema/tx/spring-tx.xsd">
  11.     <!-- 数据库连接的数据源 -->
  12.     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  13.         <!-- 数据库连接驱动 -->
  14.         <property name="driverClassName" value="${jdbc.driverClassName}" />
  15.         <!-- 连接的用户名 -->
  16.         <property name="username" value="${jdbc.username}" />
  17.         <!-- 连接的用户密码 -->
  18.         <property name="password" value="${jdbc.password}" />
  19.         <!-- 连接的url地址 -->
  20.         <property name="url" value="${jdbc.url}" />
  21.     </bean>
  22.     <!--sessionFactory工厂 -->
  23.     <bean id="localSessionFactoryBean"
  24.         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  25.         <property name="dataSource" ref="dataSource" />
  26.         <property name="mappingResources">
  27.             <array>
  28.                 <value>www/csdn/spring/demo/domain/Admins.hbm.xml</value>
  29.                 <value>www/csdn/spring/demo/domain/Atusers.hbm.xml</value>
  30.                 <value>www/csdn/spring/demo/domain/Collctions.hbm.xml</value>
  31.                 <value>www/csdn/spring/demo/domain/Comments.hbm.xml</value>
  32.                 <value>www/csdn/spring/demo/domain/Messages.hbm.xml</value>
  33.                 <value>www/csdn/spring/demo/domain/Pictures.hbm.xml</value>
  34.                 <value>www/csdn/spring/demo/domain/PrivateLetter.hbm.xml</value>
  35.                 <value>www/csdn/spring/demo/domain/Relation.hbm.xml</value>
  36.                 <value>www/csdn/spring/demo/domain/UserInfo.hbm.xml</value>
  37.                 <value>www/csdn/spring/demo/domain/Users.hbm.xml</value>
  38.             </array>
  39.         </property>
  40.         <property name="hibernateProperties">
  41.             <props>
  42.                 <prop key="hibernate.show_sql">true</prop>
  43.                 <prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory
  44.                 </prop>
  45.                 <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
  46.             </props>
  47.         </property>
  48.     </bean>
  49.     <!-- 配置HibernateTemplate -->
  50.     <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
  51.         <property name="sessionFactory" ref="localSessionFactoryBean" />
  52.     </bean>
  53.     <!-- 实现hibernateDaoSupport抽象接口来使用 -->
  54.     <bean id="hibernateDaoSupport"
  55.         class="org.springframework.orm.hibernate3.support.HibernateDaoSupport"
  56.         abstract="true">
  57.         <property name="hibernateTemplate" ref="hibernateTemplate" />
  58.     </bean>
  59.     <!-- 创建hibernate事务管理器 -->
  60.     <bean id="hibernateTransactionManager"
  61.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  62.         <property name="sessionFactory" ref="localSessionFactoryBean" />
  63.     </bean>
  64.     <!-- 事务的通知 -->
  65.     <tx:advice id="txAdvice" transaction-manager="hibernateTransactionManager">
  66.         <!-- 事务的属性 -->
  67.         <tx:attributes>
  68.             <!-- 事务的具体执行方法 -->
  69.             <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT" />
  70.             <tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT" />
  71.             <tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT"
  72.                 read-only="true" />
  73.         </tx:attributes>
  74.     </tx:advice>
  75.     <!-- 切面 -->
  76.     <aop:config>
  77.         <aop:pointcut expression="execution(* *..service.*.*(..))"
  78.             id="mycut" />
  79.         <aop:advisor advice-ref="txAdvice" pointcut-ref="mycut" />
  80.     </aop:config>
  81. </beans>

本文固定链接: http://www.devba.com/index.php/archives/705.html | 开发吧

报歉!评论已关闭.