国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
spring tx:advice 和 aop:config
spring tx:advice 和 aop:config 配置事務
2010-03-22 14:32
關鍵字: eclipse不能識別<tx:advice/>標簽
<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    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 "
>

<bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager"
        abstract="false" lazy-init="default" autowire="default"
        dependency-check="default">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="add*" propagation="REQUIRED" />
            <!-- <tx:method name="*" propagation="true" />-->
        </tx:attributes>

    </tx:advice>

    <aop:config>
        <aop:pointcut id="allManagerMethod"
            expression="execution(* com.service.*.*(..))" />
        <aop:advisor advice-ref="txAdvice"
            pointcut-ref="allManagerMethod" />
    </aop:config>
</beans>


Eclipse不能識別<tx:advice/>標簽

在開發(fā)Spring的過程中,有時會出現(xiàn)Eclipse不能識別<tx:advice/>標簽。

提示出現(xiàn)以下錯誤:

The prefix "tx" for element "tx:advice" is not bound



這個錯誤的原因很簡單是:

我們在定義申明AOP的時候。。沒有加載schema。

具體表現(xiàn)如下:

<beans>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
     <tx:attributes>
         <tx:method name="get*" read-only="true"/>
         <tx:method name="*" propagation="REQUIRES_NEW" rollback-for="Exception"/>
     </tx:attributes>
</tx:advice>

<!-- aop代理設置-->
<aop:config proxy-target-class="true">  
....

</aop:config>

</beans>

這時會拋出異常不認<TX>標簽。。起先還以為是沒有加載JAR包呢。。

后來讀AOP文檔才發(fā)現(xiàn)<beans>中要加入“xmlns:aop”的命名申明,并在“xsi:schemaLocation”中指定aop配置的schema的地址

配置文件如下:

<?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: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.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 ">

這些才是最關鍵的地方。。后面的配置不變。。。。


Spring使用 <tx:advice>和 <aop:config> 用來配置事務,具體如何配置你可以參考Spring文檔。

我解釋一下(* com.evan.crm.service.*.*(..))中幾個通配符的含義:

第一個 * —— 通配 任意返回值類型
第二個 * —— 通配 包com.evan.crm.service下的任意class
第三個 * —— 通配 包com.evan.crm.service下的任意class的任意方法
第四個 .. —— 通配 方法可以有0個或多個參數(shù)

綜上:包com.evan.crm.service下的任意class的具有任意返回值類型、任意數(shù)目參數(shù)和任意名稱的方法

 

<tx:advice/> 有關的設置

這一節(jié)里將描述通過 <tx:advice/> 標簽來指定不同的事務性設置。默認的 <tx:advice/> 設置如下:

 

  • 事務傳播設置是 REQUIRED

  • 隔離級別是 DEFAULT

  • 事務是 讀/寫

  • 事務超時默認是依賴于事務系統(tǒng)的,或者事務超時沒有被支持。

  • 任何 RuntimeException 將觸發(fā)事務回滾,但是任何 checked Exception 將不觸發(fā)事務回滾

 

這些默認的設置當然也是可以被改變的。 <tx:advice/><tx:attributes/> 標簽里的 <tx:method/> 各種屬性設置總結如下:

 

表 9.1. <tx:method/> 有關的設置 屬性 是否需要? 默認值 描述 name 是 與事務屬性關聯(lián)的方法名。通配符(*)可以用來指定一批關聯(lián)到相同的事務屬性的方法。 如:'get*'、'handle*'、'on*Event'等等。 propagation 不 REQUIRED 事務傳播行為 isolation 不 DEFAULT 事務隔離級別 timeout 不 -1 事務超時的時間(以秒為單位) read-only 不 false 事務是否只讀? rollback-for 不 將被觸發(fā)進行回滾的 Exception(s);以逗號分開。 如:'com.foo.MyBusinessException,ServletException' no-rollback-for 不 不 被觸發(fā)進行回滾的 Exception(s);以逗號分開。 如:'com.foo.MyBusinessException

 

本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
applicationContext 中 xmlns 與 xsi:schemaLocation 含義
springmvc3.2.2+hibernate4.2.1(一)
Freemark與Spring MVC的整合
spring框架
Spring 使用 XML 配置聲明式事務
在Spring 2中整合DWR 2
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服