【问题标题】:spring data jpa and commons compatibilityspring data jpa 和 commons 兼容性
【发布时间】:2015-05-28 08:59:40
【问题描述】:

我遇到了一个使用 spring data jpa 运行项目的异常

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 18 in XML document from class path resource [META-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; systemId: http://www.springframework.org/schema/data/jpa/spring-jpa.xsd; lineNumber: 18; columnNumber: 51; src-resolve: Cannot resolve the name 'repository:repositories' to a(n) 'type definition' component.

我阅读了许多文档和博客,我认为这可能是由于 spring data jpa 和 spring data commons 包版本不兼容造成的。

现在我正在使用

  • spring-data-commons-core-1.4.1.Release
  • spring-data-commons-1.10.0.release
  • 弹簧数据-jpa-1.8.0。

对版本控制有什么建议可以消除此类错误吗?

另外,我想请教如何使此类版本控制更容易(任何网站、文档或工具)。提前感谢您的建议。

下面是我使用的命名空间

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:repository="http://www.springframework.org/schema/data/repository"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
       http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd">

repository:repository 不是来自我的applicationContext.xml。我确实使用jpa:repository作为

<jpa:repositories base-package="com.canreef.calendar"/>

【问题讨论】:

  • 我确实使用了 jpa:repository
  • @Deinum 我确实使用了 jpa:repository,那个 repository:repository 必须来自一个 xml。我已经添加到帖子中,请检查。
  • 如前所述,不要自己搜索依赖​​项,使用 maven 为您做这件事...为您省去了很多麻烦。删除 spring-data-commons-core jar,因为它已经很旧了,真的很旧......还有,为什么你的声明中需要 spring-repository.xsd?如果您不使用它,只需将其删除。
  • @Deinum 感谢您的建议,但不幸的是,删除 repository.xsd 依赖项并没有帮助。我在命名空间中删除了与存储库相关的条目,但异常是相同的。

标签: spring jpa version-control spring-data-jpa spring-data-commons


【解决方案1】:

我在 spring-repository.xsd 中找到了这个根源 在 spring-jpa.xsd 中有一行 ref to repository:auditing-attributes:

<xsd:element name="auditing">
        <xsd:annotation>
            <xsd:appinfo>
                <tool:annotation>
                    <tool:exports type="org.springframework.data.jpa.domain.support.AuditingEntityListener" />
                    <tool:exports type="org.springframework.data.auditing.AuditingHandler" />
                </tool:annotation>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:attributeGroup ref="repository:auditing-attributes" />
        </xsd:complexType>
    </xsd:element>

在 spring-repository.xsd 中有 bean:

-<xsd:attributeGroup name="auditing-attributes">


-<xsd:attribute name="auditor-aware-ref">


-<xsd:annotation>


-<xsd:documentation>

<![CDATA[ References a bean of type AuditorAware to represent the current principal. ]]>

</xsd:documentation>


-<xsd:appinfo>


-<tool:annotation kind="ref">

<tool:assignable-to type="org.springframework.data.domain.AuditorAware"/>

</tool:annotation>

</xsd:appinfo>

</xsd:annotation>

</xsd:attribute>


...omitted...

</xsd:attributeGroup>

因此这应该是由于无法获取 repository.xsd 造成的。

【讨论】:

  • 有没有人知道这个 spring-repository.xsd 所在的位置?我在任何罐子里都找不到它。
  • 由于这似乎是另一个问题,我只是启动了另一个线程stackoverflow.com/questions/30542876/…
猜你喜欢
  • 2020-11-26
  • 1970-01-01
  • 2021-06-12
  • 1970-01-01
  • 2018-10-11
  • 2019-12-26
  • 2019-08-27
  • 1970-01-01
  • 2020-04-24
相关资源
最近更新 更多