zoukankan      html  css  js  c++  java
  • spring给予XML配置的声明式事务

    步骤:

    1.添加aop、tx命名空间声明;

    2.配置事务管理器;

    3.配置增强;

    4.配置aop

    具体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: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-3.1.xsd
    	http://www.springframework.org/schema/aop 
    	http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
    	http://www.springframework.org/schema/tx 
    	http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    	">
    
    	<bean id="dataSource"
    		class="org.apache.commons.dbcp.BasicDataSource">
    		<property name="driverClassName"
    			value="oracle.jdbc.driver.OracleDriver">
    		</property>
    		<property name="url"
    			value="jdbc:oracle:thin:@localhost:1521:orcl">
    		</property>
    		<property name="username" value="system"></property>
    		<property name="password" value="ok"></property>
    	</bean>
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource">
    			<ref bean="dataSource" />
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">
    					org.hibernate.dialect.Oracle9Dialect
    				</prop>
    			</props>
    		</property>
    		<property name="mappingResources">
    			<list>
    				<value>com/it/entity/Stu.hbm.xml</value></list>
    		</property>		
    	</bean>
    	<!-- spring声明式事务  3个步骤-->
    	<!-- 1 事务管理器 -->
    	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory"/>	
    	</bean>
    	<!-- 2 增强 -->
    	<tx:advice id="tx" transaction-manager="transactionManager">
    		<tx:attributes>
    			<tx:method name="batch*"/>
    		</tx:attributes>
    	</tx:advice>
    	<!-- 3 aop -->
    	<aop:config>
    		<aop:pointcut expression="execution(* com.it.biz.impl.*.*(..))" id="pt"/>
    		<aop:advisor advice-ref="tx" pointcut-ref="pt"/>
    	</aop:config>
    	<!-- spring声明式事务写在最上面 -->
    	
    	<!-- stuDao -->
    	<bean id="studao" class="com.it.dao.impl.StuDaoImpl">
    		<property name="sessionFactory" ref="sessionFactory"/>
    	</bean>
    	<!-- stuBiz -->
    	<bean id="stubiz" class="com.it.biz.impl.StuBizImpl">
    		<property name="studao" ref="studao"/>
    	</bean>
    	<!-- stuAction -->
    	<bean id="stuaction" class="com.it.action.StuAction">
    		<property name="stubiz" ref="stubiz"/>
    	</bean>	
    	
    </beans>


  • 相关阅读:
    Centos 7 安装配置
    日常问题
    Fluent_Python_Part1序幕,01-data-model, 数据模型
    计算机基础
    dist-packages vs site-packages
    斗地主 (NOIP2015 Day1 T3)
    字串变换 (2002 年NOIP全国联赛提高组)
    搜索
    关于动态最大子段和--线段树查询
    Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'company' in 'class java.lang.String'
  • 原文地址:https://www.cnblogs.com/archermeng/p/7537426.html
Copyright © 2011-2022 走看看