`
ice666_1
  • 浏览: 36294 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

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:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/p 
  http://www.springframework.org/schema/p/spring-p-3.0.xsd
	http://www.springframework.org/schema/tx 
  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
  http://www.springframework.org/schema/aop 
  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

	<!-- 配置hibernate.cfg.xml的外部引用 -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation" value="classpath:hibernate.cfg.xml">
		</property>
	</bean>

	<!-- 配置事物管理 -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref local="sessionFactory" />
		</property>
	</bean>

	<!-- 事务拦截 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="del*" propagation="REQUIRED" />
			<tx:method name="mod*" propagation="REQUIRED" />
			<tx:method name="*" read-only="false" />
		</tx:attributes>
	</tx:advice>
	<!-- 配置AOP(Aspect Oriented Programming(面向切面编程)) -->
	<aop:config proxy-target-class="true">
		<!-- aop:pointcut切入点,advice通知,切入代码advisor -->
		<aop:pointcut id="point" expression="execution(* com.szdp.action.*.*(..))" />
		<aop:pointcut id="point2" expression="execution(* com.szdp.imp.*.*(..))" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="point" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="point2" />
	</aop:config>

	<!-- 配置(IOC(Inversion of Control(控制反转,依赖注入))) -->
	<bean id="dbImp" class="com.szdp.imp.DBImp">
		<!-- property(属性注入方式) -->
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="test" class="com.szdp.action.Test">
		<property name="dbImp" ref="dbImp"></property>
	</bean>
</beans>

 

分享到:
评论

相关推荐

    spring事务,xml方式和注解方式

    XML方式适合于传统应用,而注解方式则更加简洁,易于理解和维护。无论选择哪种方式,Spring事务管理都能帮助我们在复杂的应用场景下保证数据的一致性和完整性。在实际开发中,可以根据项目需求和团队习惯来选择合适...

    spring事务配置的五种方式

    ### Spring事务配置的五种方式详解 #### 一、引言 在企业级应用开发中,事务处理是非常重要的一部分,特别是在涉及多个数据库操作时。Spring框架提供了强大的事务管理功能,支持编程式和声明式两种事务处理方式。...

    Spring基于XML方式配置事务

    这里我们主要探讨的是"Spring基于XML方式配置事务",这涉及到Spring的事务管理器、事务属性以及如何在XML配置文件中定义这些元素。 首先,Spring的事务管理分为两种模式:编程式事务管理和声明式事务管理。编程式...

    spring事务配置的5中方式

    下面将详细介绍Spring的五种事务配置方式。 1. **基于XML的事务配置** - **每个Bean都有一个代理**: 在这种配置方式中,每个需要事务管理的Bean都会有一个对应的代理Bean。例如,对于DAO层的UserDao,我们首先...

    spring事务配置详解

    下面将详细介绍这五种Spring 事务配置方式。 1. **基于AOP代理的声明式事务** 这是最常见的配置方式,通过AOP代理在方法调用前后自动添加事务管理逻辑。在示例配置中,`TransactionProxyFactoryBean`用于创建一个...

    Spring事务配置的五种方式

    Spring 事务配置是Spring框架中不可或缺的部分,它用于管理和协调应用程序中的事务边界,确保数据的一致性和完整性。在Spring中,事务配置主要涉及到三个核心组件:DataSource、TransactionManager以及代理机制。...

    详细说明spring事务配置的5种方式

    本文将详细介绍Spring事务配置的五种方式,帮助你深入理解如何在Spring应用中管理事务。 1. **基于XML的声明式事务管理** 第一种方式是在每个Bean上使用代理来实现事务管理。首先,配置`DataSource`,通常是`...

    spring 事务配置方式

    XML方式较繁琐,但在某些场景下更灵活,如处理复杂的事务规则。 3. **基于AspectJ的事务管理(AspectJ-based Transaction Management)** AspectJ是一种面向切面的编程(AOP)框架,Spring可以结合AspectJ实现事务...

    spring几种事务配置详解【精】

    本文将深入探讨Spring中的几种事务配置方式,帮助开发者更好地理解和运用。 1. **编程式事务管理** 编程式事务管理是在代码中显式调用事务API来控制事务的开始、提交、回滚等操作。这种方式直接在业务逻辑代码中...

    SSH三大框架整合 struts2(使用xml配置)+hibernate(使用xml配置)+spring(使用xml配置)

    在这个项目中,所有配置都采用XML文件,虽然这种方式相对直观,但随着项目的扩大,XML配置文件可能会变得庞大且难以维护。现代开发中,更倾向于使用注解配置或者Spring Boot的自动配置来简化配置过程。 总结来说,...

    Spring框架xml注解配置方式实例

    在本实例中,我们将深入探讨如何使用XML和注解结合的方式来配置Spring框架。首先,我们先来理解每个文件的作用。 1. **Maven配置文件pom.xml** Maven是一个项目管理工具,通过pom.xml文件来管理项目的构建、依赖和...

    Spring事务配置的五种方式.doc

    Spring事务配置的五种方式 Spring框架中事务配置是非常重要的一部分,通常由三个组成部分组成,即DataSource、TransactionManager和代理机制。无论采取何种配置方式,代理机制部分总是变化的,而DataSource和...

Global site tag (gtag.js) - Google Analytics