【问题标题】:Why isn't the Spring AOP XML schema properly loaded when Tomcat loads & reads beans.xml为什么 Tomcat 加载和读取 beans.xml 时没有正确加载 Spring AOP XML 模式
【发布时间】:2011-05-25 04:17:10
【问题描述】:

我正在尝试在 Eclipse 中使用 Spring's Schema Based AOP Support,但在尝试在 Tomcat 中加载配置时遇到错误。

Eclipse 中没有错误,并且自动完成功能在 aop 命名空间中正常工作,但是当我尝试将项目加载到 eclipse 中时,我得到了这个错误:

09:17:59,515 WARN XmlBeanDefinitionReader:47 - 忽略 XML 验证警告 org.xml.sax.SAXParseException: schema_reference.4: 无法读取架构文档 'http://www.springframework.org/schema/aop/spring-aop-2.5.xsd',因为 1) 找不到文档; 2) 文件无法读取; 3) 文档的根元素不是。

接着是:

严重:StandardWrapper.Throwable org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:/WEB-INF/beans.xml 中的 XML 文档中的第 39 行无效;嵌套异常是 org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: 匹配通配符是严格的,但找不到元素“aop:config”的声明。

原因:org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: 匹配的通配符是严格的,但找不到元素“aop:config”的声明。

基于此,当 Tomcat 解析 beans.xml 文件时,似乎没有读取架构,导致无法识别 <aop:config> 元素。

我的 beans.xml 文件如下:

<?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:jaxws="http://cxf.apache.org/jaxws"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
        http://cxf.apache.org/jaxws 
        http://cxf.apache.org/schemas/jaxws.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

    <!--import resource="classpath:META-INF/cxf/cxf.xml" /-->
    <!--import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /-->
    <!--import resource="classpath:META-INF/cxf/cxf-servlet.xml" /-->

    <!-- NOTE: endpointName attribute maps to wsdl:port@name & should 
                be the same as the portName attribute
                in the @WebService annotation on the IWebServiceImpl class -->
    <!-- NOTE: serviceName attribute maps to wsdl:service@name & should be 
                the same as the serviceName attribute in the @WebService 
                 annotation on the ASDIWebServiceImpl class -->
    <!-- NOTE: address attribute is the actual URL of the web service 
                (relative to web app location) -->
    <jaxws:endpoint
            xmlns:tns="http://iwebservices.ourdomain/"

            id="iwebservices"
            implementor="ourdomain.iwebservices.IWebServiceImpl"
            endpointName="tns:IWebServiceImplPort"
            serviceName="tns:IWebService"
            address="/I"
            wsdlLocation="wsdl/I.wsdl">
            <!-- To have CXF auto-generate WSDL on the fly, comment out the above wsdl 
            attribute -->

            <jaxws:features>
                    <bean class="org.apache.cxf.feature.LoggingFeature" />
            </jaxws:features>
    </jaxws:endpoint>


    <aop:config>
    <aop:aspect id="myAspect" ref="aBean">

    </aop:aspect>
    </aop:config>


</beans>

我的beans.xml 文件中的&lt;aop:config&gt; 元素是从Spring website 复制粘贴的,以尝试删除任何可能的错误源

谁能解释为什么会发生这个错误以及我可以做些什么来解决它?

【问题讨论】:

  • 试试http://www.springframework.org/schema/aop/spring-aop.xsd而不是http://www.springframework.org/schema/aop/spring-aop-2.5.xsd,看看会不会有什么不同。
  • 试过http://www.springframework.org/schema/aop/spring-aop.xsd而不是http://www.springframework.org/schema/aop/spring-aop-2.5.xsd:没有区别,发生了同样的错误
  • 感谢改进 org.life.java 的格式,我想知道我应该怎么做才能使异常更具可读性
  • 好吧,这一切看起来都不错
  • 在斯卡夫曼的事情之后似乎还可以

标签: java xml spring tomcat xsd


【解决方案1】:

检查您的 webapp 的 WEB-INF/lib 文件夹中是否有 Spring AOP jar (spring-aop.jar)。

该 jar 包含指定的 XSD。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-19
    相关资源
    最近更新 更多