亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

攔截的方式

我們公司使用的是攔截的方式。但是沒見老師講這一種。心里好沒底兒啊!這種攔截的方式是否也是常用的。https://img1.sycdn.imooc.com//5cb9f3580001ccd208580560.jpg,

正在回答

1 回答

基于TransactionProxyFactoryBean的方式(實際開發種不經常使用)

老師講過了。。。。。。。。


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

? ? ? ?xmlns:tx="http://www.springframework.org/schema/tx"

? ? ? ?xmlns:aop="http://www.springframework.org/schema/aop"

? ? ? ?xmlns:context="http://www.springframework.org/schema/context"

? ? ? ?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

? ? ? ?xsi:schemaLocation="

? ? ? ?http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

? ? ? ? http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd

? ? ? ? http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd

? ? ? ? http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

">

? ? <!--配置數據源c3p0-->

? ? <bean class="com.mchange.v2.c3p0.ComboPooledDataSource" id="dataSource">

? ? ? ? <property name="driverClass" value="com.mysql.jdbc.Driver"/>

? ? ? ? <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/test"/>

? ? ? ? <property name="user" value="root"/>

? ? ? ? <property name="password" value="root"/>

? ? </bean>


? ? <!--配置業務層實現類-->

? ? <bean class="spring.demo2.AccountServiceImpl" id="accountService">

? ? ? ? <property name="accountDao" ref="accountDao"/>

? ? </bean>


? ? <!--配置DAO類-->

? ? <bean class="spring.demo2.AccountDaoImpl" id="accountDao">

? ? ? ? <property name="dataSource" ref="dataSource"/>

? ? </bean>


? ? <!--配置事務管理器-->

? ? <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">

? ? ? ? <property name="dataSource" ref="dataSource"/>

? ? </bean>


? ? <!--配置業務層的代理-->

? ? <bean class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"

? ? ? ? ? id="transactionProxyFactoryBean">

? ? ? ? <!--目標對象-->

? ? ? ? <property name="target" ref="accountService"/>

? ? ? ? <!--注入事務管理器-->

? ? ? ? <property name="transactionManager" ref="transactionManager"/>

? ? ? ? <!--注入屬性-->

? ? ? ? <property name="transactionAttributes">

? ? ? ? ? ? <props>

? ? ? ? ? ? ? ? <!--

? ? ? ? ? ? ? ? prop的格式:

? ? ? ? ? ? ? ? PROPAGATION:事務傳播行為

? ? ? ? ? ? ? ? ISOLATIN:事務的隔離行為

? ? ? ? ? ? ? ? readOnly:只讀

? ? ? ? ? ? ? ? -Exception:發生哪些異常回滾事務

? ? ? ? ? ? ? ? +Exception:發生哪些異常事務不回滾

? ? ? ? ? ? ? ? -->

? ? ? ? ? ? ? ? <!--*代表類中的所有方法-->

? ? ? ? ? ? ? ? <prop key="*">PROPAGATION_REQUIRED</prop>

? ? ? ? ? ? </props>

? ? ? ? </property>


? ? </bean>


</beans>





0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

攔截的方式

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號