java 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: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/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">
    
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName"><value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value></property>
        <property name="url"><value>jdbc:sqlserver://10.1.1.1:1111;DatabaseName=test</value></property>
        <property name="username"><value>123</value></property>
        <property name="password"><value>123456</value></property>
    </bean>
     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource"><ref local="dataSource"/></property>
        <property name="packagesToScan" value="com.barcode.*" />
        <property name="hibernateProperties">
	        <props>
	            <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
	            <prop key="hibernate.show_sql">true</prop>
				<!--  <prop key="hibernate.hbm2ddl.auto">update</prop>-->
				<prop key="hibernate.format_sql">true</prop>
	        </props>
        </property>
    </bean>
	<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
	<tx:annotation-driven/><!-- 使用tx标签方式 也是spring提供五种事物配置方式之一 -->
	<!--hibernate事物管理器-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
        <!--  <qualifier value="barcode"/> -->
    </bean>
        <!--定义Spring的事务拦截器TransactionInterceptor -->
    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
	    <!--  依赖注入上面定义的事务管理器  transactionManager -->
        <property name="transactionManager" ref="transactionManager"/>
      	<!-- 定义需要进行事务拦截的方法及所采用的事务控制类型 -->    	
    	<property name="transactionAttributes">		    
		    <props>
			    <!-- 以browse、list、load、get及is开头的所有方法采用只读型事务控制类型 -->
			    <prop key="createNewItemMaster">PROPAGATION_REQUIRED,readOnly</prop>
			    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
			    <prop key="listAllItemMasterJob">PROPAGATION_REQUIRED,readOnly</prop>
			    <prop key="delItemMastersService">PROPAGATION_REQUIRED,readOnly</prop>
			    <prop key="updateItemMasterService">PROPAGATION_REQUIRED,readOnly</prop>
			    <!-- 所有方法均进行事务控制,如果当前没有事务,则新建一个事务 -->
		    	<prop key="*">PROPAGATION_REQUIRED</prop>
		    </props>
	    </property>
	</bean>
</beans>


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值