`
huangronaldo
  • 浏览: 220572 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

Spring事务配置

 
阅读更多

   总结一下在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:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">


	<bean id="dateSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName">
			<value>oracle.jdbc.driver.OracleDriver</value>
		</property>
		<property name="url">
		<!--  jdbc:microsoft:sqlserver://127.0.0.1:1433  -->
			<value>jdbc:oracle:thin:@192.168.133.207:1521:oracle</value>
		</property>
		<property name="username">
			<value>oracle</value>
		</property>
		<property name="password">
			<value>oracle</value>
		</property>

	</bean>

	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref local="dateSource" />
		</property>
		<property name="mappingResources">
			<list>
				<value>com/zjsoft/bean/SystemUser.hbm.xml</value>
			</list>
		</property>

		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>

			<!-- 	<prop key="hibernate.show_sql">true</prop>   -->
				
				<prop key="hibernate.format_sql">true</prop>
			</props>
		</property>
	</bean>


	<!-- 事务 -->
   <!--
	<bean id="transactionManager"  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref local="sessionFactory"/>
        </property>
    </bean>
  txProxyTemplate 是一个抽象的定义,
    	  全部业务逻辑Bean的定义将继承其定义,
    	  从而获得Spring的配置式事务能力 
    -->
		<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref local="sessionFactory" />
		</property>
	</bean>

	<bean id="txProxyTemplate" abstract="true"
		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributes">
			<props>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
				<prop key="update*">PROPAGATION_REQUIRED</prop>
				<prop key="delete*">PROPAGATION_REQUIRED</prop>
				<prop key="remove*">PROPAGATION_REQUIRED</prop>
				<prop key="cancel*">PROPAGATION_REQUIRED</prop>
				<prop key="create*">PROPAGATION_REQUIRED</prop>
				<prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="search*">PROPAGATION_REQUIRED,readOnly</prop>
				<!--  <prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>  -->
				<prop key="login">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>

      <bean id="systemUserDAO" class="com.zjsoft.dao.impl.SystemUserDAOImpl" scope="singleton">
	  <property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>

   <bean id="systemUserServiceTarget" class="com.zjsoft.service.impl.SystemUserServiceImpl">
 		<property name="systemUserDAO" ref="systemUserDAO"></property>
    </bean>
	<bean id="systemUserService" parent="txProxyTemplate" scope="singleton">
		<property name="target" ref="systemUserServiceTarget" />
	</bean>

</beans>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics