【问题标题】:getting error that no declaration can be found for element 'jpa:repositories'出现错误,找不到元素'jpa:repositories'的声明
【发布时间】:2013-05-25 07:30:27
【问题描述】:

我收到以下错误

Line 84 in XML document from class path resource [car-job-app-context.xml] is 
invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 84; 
columnNumber: 154; cvc-complex-type.2.4.c: The matching wildcard is strict, but
no declaration can be found for element 'jpa:repositories'.

这是我的文件

<?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:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:tx="http://www.springframework.org/schema/tx"
    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-3.2.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.2.xsd
                        http://www.springframework.org/schema/jdbc
                        http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
                        http://www.springframework.org/schema/data/repository
                        http://www.springframework.org/schema/data/repository/spring-repository.xsd
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
                        http://www.springframework.org/schema/data/jpa
                        http://www.springframework.org/schema/data/jpa/spring-jpa-2.0.xsd" >

.....

<context:annotation-config/>

<context:component-scan base-package="pk.training.basitMahmood.service.impl" />

<jpa:repositories base-package="pk.training.basitMahmood.repository" entity-manager-factory-ref="emf" transaction-manager-ref="transactionManager" />

这是我的 maven 依赖项的快照

我还看到了相同的链接,上面写着在context 之后移动tx declaration,但它不起作用。 same post as my question。我在组合之前和之后尝试过,但错误仍然存​​在。

为什么我会收到这个错误?我无法在数据库中保存数据....?

谢谢

【问题讨论】:

    标签: spring jpa-2.0


    【解决方案1】:

    命名空间的顺序无关紧要。确保 spring-data-jpa 工件在您的类路径中,并仔细检查架构版本。没有 spring-jpa-2.0 这样的东西。它应该在 1.0 和 1.3 之间。使用 Spring,您通常也可以省略版本并默认获取最新的架构。

    【讨论】:

    • 您可以在图片中看到我的 maven 依赖项中有 spring-data-jpa-1.3.2.RELEASE.jar 吗?你可以看到我所有的罐子。
    • 还有一点,除了`springframework.org/schema/data/jpa/spring-jpa-1.3.xsd"`之外的每个链接都在打开,我也尝试了`springframework.org/schema/data/jpa/spring-jpa.xsd"`,但我找不到页面?
    • 它开始工作,我不知道,但我在http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd "&gt; 行中放了一个空格,然后它开始工作,虽然我再次删除了空格,但它仍然工作。我不知道为什么这以前不起作用。但至少你让我想到了检查有关 xsd 的链接是否打开。您还说顺序无关紧要。所以谢谢你的帮助:-)
    【解决方案2】:

    问题在于 bean 模式的定义。

    更改xmlns="http://www.springframework.org/schema/beans"

    对于xmlns:beans="http://www.springframework.org/schema/beans"

    【讨论】:

      【解决方案3】:

      你可以加入豆子;

      xmlns:jpa="http://www.springframework.org/schema/data/jpa"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-12
        • 1970-01-01
        相关资源
        最近更新 更多