Spring OXM中的“context-path”错误

时间:2014-08-29 05:47:23

标签: spring marshalling oxm

我有一个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项目中创建marshaller时,它看起来像这样:

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

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

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

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

1 个答案:

答案 0 :(得分:1)

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

中定义