1. 程式人生 > >The prefix "tx" for element "tx:advice" is not bound 錯誤的說明

The prefix "tx" for element "tx:advice" is not bound 錯誤的說明

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

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

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

具體表現如下:

<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文件才發現<beans>中要加入“xmlns:aop”的命名申明,並在“xsi:schemaLocation”中指定aop配置的schema的地址

配置檔案如下:

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

希望能幫助別人解決此類的小問題