Spring AOP匹配通配符严格,但是对于元素'aop:config'没有声明可以找到
从类路径资源的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
你能告诉我什么,请上午我错过了?
您需要添加到您的schemaLocation:
xsi:schemaLocation="
...
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
...
"
现在我得到这个:-(异常在线程“main”org.springframework.beans.factory.BeanDefinitionStoreException:意外的异常从类路径资源解析XML文档[ApplicationContextAOP.xml];嵌套的异常是java.lang.NoClassDefFoundError:org/aopalliance/aop/Advice – Aubergine
你错过了[aopalliance jar](http://search.maven.org/#artifactdetails|aopalliance|aopalliance|1.0|jar)。 –
@Aerdegine:你应该接受这个答案为正确的答案并提出一个新的问题 –
我们收到了类似的错误消息的元素tx:advice
,得到它与org.springframework.*-3.1.2.RELEASE.jar
S其中*
代表罐子模块更换org.springframework.*-3.0.0.M3.jar
小号解决。因此,尝试获得稳定的版本以解决类似的问题。
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"
非常感谢您的提问。我面临同样的问题,但在我的情况下,问题是我缺少classpath中的'spring-aop.jar';那是我错过的。感谢您将此引起我的注意。 – manuelvigarcia