【问题标题】:'context-path' error in Spring OXMSpring OXM 中的“上下文路径”错误
【发布时间】:2014-08-29 05:47:23
【问题描述】:

我有一个 Grails 项目,它有一个依赖项,这是我的另一个项目,它使用 spring-oxm。我的 Grails 项目可以成功 <import resource="some.xml"> 位于 .jar 内的 .xml 但它显示此错误:

Attribute 'context-path' is not allowed to appear in element 'oxm:jaxb2-marshaller'

我的 Grails BuildConfig.groovy 有这种依赖关系:

    compile ('org.springframework:spring-oxm:3.1.0.RELEASE')

这对我的其他 (Maven) 项目的依赖:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>3.1.0.RELEASE</version>
    </dependency>

这是我为 oxm-marshaller 创建 bean 的方式:

<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
     <property name="contextPath" value="com.somepackage.commons"/>
</bean>

此外,每当我运行 Maven 项目的测试时,spring 应用程序上下文都会完美加载,这就是为什么我确信它可以独立运行的原因。

这里有什么问题?我在两个项目中都使用了相同的 spring-oxm 依赖项,为什么我仍然会遇到这些错误?需要帮助!

编辑:快速解决方法……我没有将我的 Maven 项目作为依赖项导入,而是尝试将我的 Maven 项目中的所有代码复制粘贴到 Grails 项目中,它工作得很好……仍然想知道这里出了什么问题:(

编辑 2:我尝试以不同的方式创建 bean……我没有创建 Spring bean 本身,而是使用了 oxm 命名空间。当我在我的 Maven 项目中创建编组器时,它看起来像这样:

<oxm:jaxb2-marshaller id="marshaller" context-path="com.somepackage.commons"/>

有趣的是,在我的 Grails 项目(我之前复制粘贴的那个)中,它看起来像这样:

<oxm:jaxb2-marshaller id="marshaller" contextPath="com.somepackage.commons"/>

注意 contextPath 属性的 camelCase 约定。为什么会这样?

【问题讨论】:

  • 我发现了同样的行为。事实上,Spring Tool Suite 的 xml 编辑器抱怨“contextPath”无效,但 Maven 不会编译,除非它是驼峰式的。我还没有调查这两者的分歧之处以及原因。

标签: spring marshalling oxm


【解决方案1】:

检查类路径中的实际 spring oxm jar 是否指向正确的 xsd。 您将在 META-INF/spring.schemas 文件中找到该指针。 spring-oxm-3.x.xsd 中没有定义“context-path”属性。它在spring-oxm-4.x.xsd中定义

【讨论】:

    猜你喜欢
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多