【转帖】spring的事务配置Xml方式

Xml代码 

 收藏代码

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
  4.     xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"  
  5.     xsi:schemaLocation="  
  6.     http://www.springframework.org/schema/beans  
  7.     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  8.     http://www.springframework.org/schema/p   
  9.   http://www.springframework.org/schema/p/spring-p-3.0.xsd  
  10.     http://www.springframework.org/schema/tx   
  11.   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
  12.   http://www.springframework.org/schema/aop   
  13.   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">  
  14.   
  15.     <!-- 配置hibernate.cfg.xml的外部引用 -->  
  16.     <bean id="sessionFactory"  
  17.         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  18.         <property name="configLocation" value="classpath:hibernate.cfg.xml">  
  19.         </property>  
  20.     </bean>  
  21.   
  22.     <!-- 配置事物管理 -->  
  23.     <bean id="transactionManager"  
  24.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  25.         <property name="sessionFactory">  
  26.             <ref local="sessionFactory" />  
  27.         </property>  
  28.     </bean>  
  29.   
  30.     <!-- 事务拦截 -->  
  31.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  32.         <tx:attributes>  
  33.             <tx:method name="add*" propagation="REQUIRED" />  
  34.             <tx:method name="del*" propagation="REQUIRED" />  
  35.             <tx:method name="mod*" propagation="REQUIRED" />  
  36.             <tx:method name="*" read-only="false" />  
  37.         </tx:attributes>  
  38.     </tx:advice>  
  39.     <!-- 配置AOP(Aspect Oriented Programming(面向切面编程)) -->  
  40.     <aop:config proxy-target-class="true">  
  41.         <!-- aop:pointcut切入点,advice通知,切入代码advisor -->  
  42.         <aop:pointcut id="point" expression="execution(* com.szdp.action.*.*(..))" />  
  43.         <aop:pointcut id="point2" expression="execution(* com.szdp.imp.*.*(..))" />  
  44.         <aop:advisor advice-ref="txAdvice" pointcut-ref="point" />  
  45.         <aop:advisor advice-ref="txAdvice" pointcut-ref="point2" />  
  46.     </aop:config>  
  47.   
  48.     <!-- 配置(IOC(Inversion of Control(控制反转,依赖注入))) -->  
  49.     <bean id="dbImp" class="com.szdp.imp.DBImp">  
  50.         <!-- property(属性注入方式) -->  
  51.         <property name="sessionFactory" ref="sessionFactory"></property>  
  52.     </bean>  
  53.     <bean id="test" class="com.szdp.action.Test">  
  54.         <property name="dbImp" ref="dbImp"></property>  
  55.     </bean>  
  56. </beans>  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值