spring給予XML配置的聲明式事務

來源:互聯網
上載者:User

步驟:

1.添加aop、tx命名空間聲明;

2.配置交易管理員;

3.配置增強;

4.配置aop

具體xml設定如下:

<?xml version="1.0" encoding="UTF-8"?><beansxmlns="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.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsdhttp://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>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.