Spring声明式事务管理,采用xml配置的配置文件如下:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" 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/aop
http://www.springframework.org/schema/aop/spring-aop-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/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 打开Annotation注入 -->
<context:annotation-config />
<context:component-scan base-package="com.spring" />
<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.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.spring.model.User</value>
<value>com.spring.model.Log</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>
<!--
the transactional advice (what 'happens'; see the <aop:advisor/> bean
below)
-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!--
all methods starting with 'get' are read-only
调用readOnly的Connection,以提高性能
-->
<tx:method name="get*" read-only="true" />
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="sa*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<!--
ensure that the above transactional advice runs for any execution of
an operation defined by the FooService interface
-->
<aop:config>
<!-- 定义一个切面 -->
<aop:pointcut id="bussinessPointcut"
expression="execution(public * com.spring..*.*(..))" />
<!--
定义一个建议者 即对于满足bussinessPointcut这个条件的方法方法提供txAdvice建议
-->
<aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessPointcut" />
</aop:config>
<!--
a PlatformTransactionManager is still required 定义了一个事务管理器
-->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!-- (this dependency is defined somewhere else) -->
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
分享到:
相关推荐
Xml文件配置实现声明式事务管理 Xml文件配置实现声明式事务管理
<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans" xmlns:xsi=...
Spring使用XML配置声明式事务 ,具体效果和过程看博文 http://blog.csdn.net/evankaka/article/details/45478007
5.2.2 基于Annotation方式的声明式事务 基于Annotation方式的声明式事务 1 在Spring容器中注册事务注解驱动; 2 在需要事务管理的类或方法上使用@... 基于XML方式的声明式事务是在配置文件中通过元素配置事务规则来实现
发布于2013-5-6项目使用SSH架构,现在要添加Spring事务管理功能,针对当前环境,只需要添加Spring2.0AOP类库即可。添加方法:点击项目右键->BuildPath->Addlibrarys:打开AddLibraries对话框,然后选定...
spring声明式事务的配置 3. spring2.0配置事务 a) 将spring 1.2升级到spring2.0 i. 去掉spring1.2相关的包 ii. 添加spring2.0的jar包:spring.jar,aspecjrt.jar,aspectjweaver.jar 和cglib-nodep-2.1.3,jar iii. ...
Spring提供了声明式事务处理机制,它基于AOP实现,无须编写任何事务管理代码,所有的工作全在配置文件中完成。 二、声明式事务的XML配置方式 为业务方法配置事务切面,需要用到tx和aop两个命名空间下的标签,先在...
声明式事务管理也有两种常用的方式,一种是基于tx和aop名字空间的xml配置文件,另一种就是基于@Transactional注解。显然基于注解的方式更简单易用,更清爽。spring注解事务实现demo
spring-1 演示了使用setter方式及构造器方式创建bean,util:list标签创建集合,p标签简化配置 和依赖注入, 以及bean的autowire和继承与依赖,以及bean的作用域...spring-5 演示了声明式事务及使用xml配置文件处理事务
15、Spring基于XML方式的声明式事务控制 16、Spring基于注解方式声明式事务控制 SpringMVC部分: 1、SpringMVC简介 2、SpringMVC组件解析 3、SpringMVC数据响应 4、SpringMVC数据请求 5、SpringMVC文件上传 6、...
JdbcDaoSupport、使用 NamedParameterJdbcTemplate、Spring 的声明式事务、事务的属性(传播行为、隔离级别、回滚属性、只读属性、过期时间)、使用 XML 文件的方式配置事务、整合 Hibernate、整合 Struts2 等。
5.1.8声明式事务管理 116 5.1.8.1Spring的事务管理器 117 5.1.8.2Spring事务的传播属性 117 5.1.8.3Spring事务的隔离级别 117 拓展: 118 5.1.8.4以XML配置的 形式 119 拓展: 120 5.1.8.5以注解方式配置 125 拓展:...
9.5.1. 理解Spring的声明式事务管理实现 9.5.2. 第一个例子 9.5.3. 回滚 9.5.4. 为不同的bean配置不同的事务语义 9.5.5. <tx:advice/> 有关的设置 9.5.6. 使用 @Transactional 9.5.7. 插入事务操作 9.5.8. ...
9.5.1. 理解Spring的声明式事务管理实现 9.5.2. 第一个例子 9.5.3. 回滚 9.5.4. 为不同的bean配置不同的事务语义 9.5.5. <tx:advice/> 有关的设置 9.5.6. 使用 @Transactional 9.5.6.1. @Transactional 有关的设置 ...
9.5.1. 理解Spring的声明式事务管理实现 9.5.2. 第一个例子 9.5.3. 回滚 9.5.4. 为不同的bean配置不同的事务语义 9.5.5. <tx:advice/> 有关的设置 9.5.6. 使用 @Transactional 9.5.7. 插入事务操作 9.5.8. ...
9.5.1. 理解Spring的声明式事务管理实现 9.5.2. 第一个例子 9.5.3. 回滚 9.5.4. 为不同的bean配置不同的事务语义 9.5.5. <tx:advice/> 有关的设置 9.5.6. 使用 @Transactional 9.5.7. 事务传播 9.5.8. 通知...
SpringMVC跟MyBatis配合使用的例子 1、web.xml中配置Spring 2、web.xml中配置SpringMVC ...8、创建SpringTx配置文件配置声明式事务 9、创建SpringMVC配置文件配置SpringMVC的注解驱动、视图解析器和组件扫描
spring-core.jar(必须):这个jar 文件包含Spring 框架...spring-tx.jar:为JDBC、Hibernate、JDO、JPA等提供的一致的声明式和编程式事务管理。 spring-webmvc-portlet.jar:Spring MVC的增强 spring-websocket.jar:
9.5.1. 理解Spring的声明式事务管理实现 9.5.2. 第一个例子 9.5.3. 回滚 9.5.4. 为不同的bean配置不同的事务语义 9.5.5. <tx:advice/> 有关的设置 9.5.6. 使用 @Transactional 9.5.7. 事务传播 9.5.8. 通知...