2011-08-19 104 views
9

從類路徑資源的XML文檔中的第13行[ApplicationContextAOP.xml]無效;嵌套異常是org.xml.sax.SAXParseException:cvc-complex-type.2.4.c:匹配的通配符是嚴格的,但是對於元素'aop:config'沒有聲明。Spring AOP匹配通配符嚴格,但是對於元素'aop:config'沒有聲明可以找到

<?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:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 
<bean id="audience" class="com.idol.Audience" /> 

<aop:config> 
<aop:aspect ref="audience"> 

    <!-- Before performance -->  

    <aop:before pointcut="execution(*com.idol.performers.Performer.perform(..))" 
    method="takeSeats"/> 

    <aop:before pointcut="execution(*com.idol.performers.Performer.perform(..))" 
    method="turnOffCellPhones" /> 

    <!-- After performance --> 

    <aop:after-returning pointcut="execution(*com.idol.performers.Performer.perform(..))" 
    method="applaud" /> 

    <!-- After bad performance(exception thrown) -->  

    <aop:after-throwing pointcut="execution(*com.idol.performers.Performer.perform(..))" 
    method="demandRefund" /> 

</aop:aspect> 
</aop:config> 
<bean id="poeticDuke" class="com.idol.performers.PoeticJuggler"> 
<constructor-arg value = "15" /> 
<constructor-arg ref = "sonnet29" /> 
</bean> 

</beans> 

我已經看到了類似的錯誤,我敢肯定我的類路徑有org.springframework.aop-3.1.0.M2.jar

你能告訴我什麼,請上午我錯過了?

+0

非常感謝您的提問。我面臨同樣的問題,但在我的情況下,問題是我缺少classpath中的'spring-aop.jar';那是我錯過的。感謝您將此引起我的注意。 – manuelvigarcia

回答

22

您需要添加到您的schemaLocation:

xsi:schemaLocation=" 
... 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
... 
" 
+0

現在我得到這個:-(異常在線程「main」org.springframework.beans.factory.BeanDefinitionStoreException:意外的異常從類路徑資源解析XML文檔[ApplicationContextAOP.xml];嵌套的異常是java.lang.NoClassDefFoundError:org/aopalliance/aop/Advice – Aubergine

+3

你錯過了[aopalliance jar](http://search.maven.org/#artifactdetails|aopalliance|aopalliance|1.0|jar)。 –

+1

@Aerdegine:你應該接受這個答案爲正確的答案並提出一個新的問題 –

0

我們收到了類似的錯誤消息的元素tx:advice,得到它與org.springframework.*-3.1.2.RELEASE.jar S其中*代表罐子模塊更換org.springframework.*-3.0.0.M3.jar小號解決。因此,嘗試獲得穩定的版本以解決類似的問題。

0
 
Adding one more possibility to the earlier provided answers : 

Wrong version of schemaLocation: 
http://www.springframework.org/schema/aop/ 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 

Correct Version: 
http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 

REASON: The extra "/" after "schema/aop" 
相關問題