The prefix "tx" for element "tx:advice" is not bound spring
這個錯誤的緣由很簡單是: spa
咱們在定義申明AOP的時候。。沒有加載schema。 代理
具體表現以下: xml
<beans> element
<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">
.... get
</aop:config> io
</beans> class
這時會拋出異常不認<TX>標籤。。起先還覺得是沒有加載JAR包呢。。 配置
後來讀AOP文檔才發現<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">
這些纔是最關鍵的地方。。後面的配置不變。。。。
但願能幫助別人解決此類的小問題