`

spring的事务配置完整例子

阅读更多
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config />
<context:component-scan base-package="com.gff" />


<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean>

<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/gff/ssh/entity/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

   <aop:config>
   <aop:pointcut id="businessmethod" expression="execution(* com.gff.ssh.serviceimpl.*.*(..))" />
   <aop:advisor pointcut-ref="businessmethod" advice-ref="txAdvice"/>
   </aop:config>
  
   <tx:advice id="txAdvice" transaction-manager="txManager">
   <tx:attributes>
   <tx:method name="add*" propagation="REQUIRED"/>
   <tx:method name="insert*" propagation="REQUIRED"/>
   <tx:method name="update*" propagation="REQUIRED"/>
   <tx:method name="del*" propagation="REQUIRED"/>
   </tx:attributes>
   </tx:advice>
<bean id="useraction" class="com.gff.ssh.action.UserAction" scope="prototype">
<property name="userService" ref="userService"/>
</bean>
<bean id="userService" class="com.gff.ssh.serviceimpl.UserServiceImpl">
<property name="userDao" ref="userDao"/>
</bean>
<bean id="userDao" class="com.gff.ssh.daoimpl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

</beans>
分享到:
评论

相关推荐

    Spring 事务配置详解(多种配置方法)

    Spring事务配置的例子。有多种方法,有传统的XML,还有Annotation等等

    Spring + Hibernate + Struts 事务配置小例子(带提示框等小技巧)

    前几天搞 Spring + Hibernate + Struts 事务配置 ,网上找了好多资料,不过好无语,大多都是 Ctrl + V,浪费俺的宝贵时间 现在我总结配出一套,给大家参考参考,可能有不足,请大家多多交流。 附:内有弹出...

    Spring-事务的配置

    一个简单通俗的例子,演示spring事务的多种配置方式

    spring事物和rabbitMQ的例子

    spring的2个数据源的配置,并且每个数据源都配置了事物管理。还有rabbitMQ的发送端代码。本人项目亲自用到的,可以运行。

    springSecurity3简单例子

    使用springSecurity3开发的一个简单例子,登录使用sql方式控制,权限使用AOP的方式配置,类似于声明式事务的配置!

    jta分布式事务完成例子,测试通过

    例子虽小,可覆盖面广,设计spring载入.properties文件,spring配置jta和jotm分布式事务,设置数据源连接池,注解事务驱动。功能是在mysql上建立了两个数据库分别为dbone和dbtwo,在dbone里有表tb1,表中只有一个字段...

    Spring3.0配置多个事务管理器的方法

    Spring3.0配置多个事务管理器(即操作多个数据源)的方法 大多数项目只需要一个事务管理器。然而,有些项目为了提高效率、或者有多个完全不同又不相干的数据源,最好用多个事务管理器。机智的Spring的Transactional...

    MyBatis3.06与Spring3.1整合例子

    MyBatis3.06与Spring3.1整合例子,配置了事务,spring采用annotation的形式

    Spring+3.x企业应用开发实战光盘源码(全)

     第9章:介绍了Spring事务管理的工作机制,通过XML、注解等方式进行事务管理配置,同时还讲解了JTA事务配置知识。  第10章:对实际应用中Spring事务管理各种疑难问题进行透彻的剖析,让读者对Spring事务管理不再有...

    spring+mybatis+事务

    Spring+mybatis的源码,同时还配置了事务管理

    spring配置文件

    spring配置文件例子,配置数据源,session工厂,事务控制。

    spring boot 全面的样例代码

    - chapter9-1-4:[Spring Cloud构建微服务架构(四)分布式配置中心](http://blog.didispace.com/springcloud4/) - chapter9-1-5:[Spring Cloud构建微服务架构(五)服务网关]...

    SpringBoot、SpringCloud的各种集成例子大全

    SpringBoot集成Atomikos框架-实现分布式数据库XA事务;...SpringCloud集成Consul框架-实现配置中心; SpringCloud集成Consul框架-实现注册中心; SpringCloud集成Consul+Ribbon框架-实现注册中心和负载均衡; 等等

    spring.doc

    5.1.8.3Spring事务的隔离级别 117 拓展: 118 5.1.8.4以XML配置的 形式 119 拓展: 120 5.1.8.5以注解方式配置 125 拓展: 127 5.1.9使用CGLIB以XML形式配置事务 130 5.2 Spring+Hibernate 131 5.2.1 ...

    Spring-Reference_zh_CN(Spring中文参考手册)

    2.4.1. 在XML里更为简单的声明性事务配置 2.4.2. JPA 2.4.3. 异步的JMS 2.4.4. JDBC 2.5. Web层 2.5.1. Spring MVC的表单标签库 2.5.2. Spring MVC合理的默认值 2.5.3. Portlet 框架 2.6. 其他特性 2.6.1. 动态语言...

    Spring.3.x企业应用开发实战(完整版).part2

    10.5.1 Spring事务管理器的应对 10.5.2 Hibernate+Spring JDBC混合框架的事务管理 10.6 特殊方法成漏网之鱼 10.6.1 哪些方法不能实施Spring AOP事务 10.6.2 事务增强遗漏实例 10.7 数据连接泄漏 10.7.1 底层连接资源...

    Spring 2.0 开发参考手册

    2.4.1. 在XML里更为简单的声明性事务配置 2.4.2. JPA 2.4.3. 异步的JMS 2.4.4. JDBC 2.5. Web层 2.5.1. Spring MVC的表单标签库 2.5.2. Spring MVC合理的默认值 2.5.3. Portlet 框架 2.6. 其他特性 2.6.1. ...

    Spring面试题含答案.pdf

    12. Spring 配置文件 13. 什么是 Spring IOC 容器? 14. IOC 的优点是什么? 15. ApplicationContext 通常的实现是什么? 16. Bean 工厂和 Application contexts 有什么区别? 17. 一个 Spring 的应用看起来象什么...

    spring.net中文手册在线版

    14.5.1.理解Spring.NET声明式事务管理的实现 14.5.2.第一个例子 14.5.3.Transaction特性的设置 14.5.4.通过AutoProxyCreator使用声明式事务 14.5.5.通过TransactionProxyFactoryObject使用声明式事务 14.5.6. 通过...

    struts2+spring+hibernate分页,事务,自定义切面

    struts2+spring+hibernate分页,事务,自定义切面,事务的配置

Global site tag (gtag.js) - Google Analytics