无法解析名称“repository:repository”为“类型定义”组件。

10

我在尝试集成Spring Data过程中遇到了这个错误。完整的堆栈跟踪如下:

nested exception is org.xml.sax.SAXParseException; systemId: http://www.springframework.org/schema/data/jpa/spring-jpa.xsd; lineNumber: 18; columnNumber: 48; src-resolve: Cannot resolve the name 'repository:repository' to a(n) 'type definition' component.
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)

XML文件是一种可扩展标记语言文件。
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://www.springframework.org/schema/data/jpa"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/data/jpa
        http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
    <repositories base-package="com.interviewedonline.poc.repositories" />


你找到解决方案了吗? - prilia
6个回答

2

我曾经遇到过与XSD文件相同的问题。

我将Spring Data Commons 1.4更改为Spring Data Commons 1.3.2,现在一切都运行得非常完美...


1

1

你需要先定义Spring Data JPA 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:jpa="http://www.springframework.org/schema/data/jpa"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/data/jpa
        http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

    <jpa:repositories base-package="com.interviewedonline.poc.repositories" />

</beans>

或者,如果您想像示例中那样使用默认的 XML 命名空间:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/data/jpa"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:beans="http://www.springframework.org/schema/beans"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/data/jpa
        http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

    <repositories base-package="com.interviewedonline.poc.repositories" />

</beans:beans>

没有运气。我已经尝试了两个选项。仍然得到相同的异常。不确定是否存在任何jar冲突。我正在使用3.1.2版本的Spring。 - Ananth Duari
@AnanthDuari:你的CLASSPATH上是否有spring-data-jpa*.jar?仅有spring*.jar是不够的。 - Tomasz Nurkiewicz
是的,我有spring-data-jpa-1.1.0.RELEASE.jar、spring-data-rest-core-1.0.0.RC3.jar、spring-data-rest-repository-1.0.0.RC3.jar和spring-data-rest-webmvc-1.0.0.RC3.jar。但仍然出现错误。 - Ananth Duari
尝试使用不同版本的XSD,问题仍然存在。即使我可以看到repository:repository。尝试使用http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd。 - Ananth Duari
我遇到了完全相同的问题 http://stackoverflow.com/questions/13246106/how-to-integrate-spring-data-jpa-and-spring-data-solr/13264352#13264352 - Tom

1
我最近在更新旧项目的依赖项时遇到了这个错误。我的问题是这个依赖项:
<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-commons-core</artifactId>
  <version>1.5.1.RELEASE</version>
</dependency>

已被重命名,现在正确的名称为:
<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-commons</artifactId>
  <version>1.8.1.RELEASE</version>
</dependency>

我已经声明了 spring-data-commons-corespring-data-commons 是 data-mongodb 的传递依赖项,结果我得到了两个 jar 包,而类加载器使用的是不正确的 spring-data-commons-core。


1

我遇到了同样的错误。添加spring-data-commons-core似乎对我有用。


请问您能否分享一下您使用的Spring(以及Spring Data和Spring Data Solr)版本号? - Tom
我正在使用Spring 3.1.1,spring-data-jpa-1.1.0和spring-data-commons-core-1.3.0。 - dnc253
1
将spring-data-commons-core的版本从1.4.0更改为1.3.0后,我遇到了java.lang.ClassNotFoundException: org.springframework.data.repository.config.RepositoryConfigurationExtension。 - Tom
@Tom 你找到解决方案了吗? - Stanley

0
在一些Spring的.jar文件中,您可以找到META-INF文件夹。您会在该文件夹中找到spring.handlers和spring.schemas。spring-data-commons-.jar确实有这些文件。如果您使用Maven,您应该在src/main/resources下创建META-INF文件夹,并将spring-data-commons- .jar中的spring.handlers,spring.schemas内容追加到您的spring.handlers,spring.schemas中。
祝您好运!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接