当前位置: 首页 > 知识库问答 >
问题:

由:org.xml.sax.SAXParseException:cvc-complex-type.2.4.c:找不到元素“jpa:repository”的声明

吴哲
2023-03-14

我在堆栈溢出中看到相同的查询和多个答案,但没有任何效果。由于在我的情况下,没有任何解决方案有效,想知道是否还有其他东西可以尝试!

例外:

Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 49 in XML document from URL [file:/C:/xxx/xxx-data/target/classes/xxx-data-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 49; columnNumber: 172; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'jpa:repositories'.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)

我的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:context="http://www.springframework.org/schema/context"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

这一行异常指向:

<jpa:repositories base-package="au.com.xxxxxxx.xxx.data.dao.bth" entity-manager-factory-ref="entityManagerFactory-slg" transaction-manager-ref="transactionManager-slg"/>

我尝试使用和不使用 JPA 版本,使用和不使用 HTTPS,验证了 XML 等等,但没有任何效果。

注意:我试图注释jpa:repositories标签,然后进入下一个问题:

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.3: Element 'beans' 

    cannot have character [children], because the type's content type is element-only.
        at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

共有2个答案

邹锦
2023-03-14

我在测试时遇到了这个问题。我是如何通过评论来解决这个问题的

@EnableJpaRepositorys(basePackages={“com.abc.xxx.data.*”},entityManagerFactoryRef=“entityManagerFactory xyz”)

这个错误似乎非常误导人。这是最好的解决方案:https://stackoverflow.com/a/59487936/3480525

但是因为那对我不起作用,我不得不注释掉它并添加注释。

潘振国
2023-03-14

根据搜索,我发现了两种值得尝试的模式,可能有效也可能无效。

缺少1个< code>xmlns:tx声明

模式的2个顺序应为context、tx、jpa

参考这些链接

<?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:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/jee 
            http://www.springframework.org/schema/jee/spring-jee.xsd
            http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context.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/util 
            http://www.springframework.org/schema/util/spring-util.xsd">
 类似资料:
  • 问题内容: 我已经在我的lib文件夹中添加了spring-security-config-3.1.0.RC3.jar,但仍然出现此错误。可能是什么原因? 这是我的dispatcher-servlet.xml 问题答案: 你有这个: 但您在这里没有提及它: 要解决这个问题,您应该 那里,就像 注意:模式引用实际上没有提到Spring版本,以便于升级,这是很常见的做法,因此您应该使用like之类的引用

  • 这个错误出现在web.xml文件的错误页标记上: cvc-complex-type.2.2:元素“location”不能有元素[childrens], 我的web.xml文件如下所示(未显示其他标记): xmlns:xsi=“http://www.w3.org/2001/xmlSchema-instance” xsi:schemalocation=“http://java.sun.com/xml/

  • 问题内容: 我有弹簧罐,并试图 从此处给出的教程中实现程序。xml配置文件为: 主要: 我不知道这些豆怎么了。到目前为止,关于其他问题的任何建议都无济于事。有什么帮助吗? 问题答案: 假设您使用的是Spring 3.1,请尝试以下操作: 在最后一行用您使用的 主要 Spring版本替换。含义:即使有Spring版本,也没有XSD 。

  • 我有这个问题 XML格式的文档 我的XSD 我有个神经衰弱的问题。有什么想法吗? 问候

  • 在spring中,每当我在dispatcher-servlet.xml中编写时,我都会得到这样的错误:-

  • 我从GitHub获取了一个android项目,并将其克隆到了我的android Studio中。当我试图运行ActivityMain时。xml文件为了检查项目是否正常工作,我遇到了这个错误“找不到元素'RelativeLayout'的声明”。我不知道怎么解决这个问题。如果任何人有任何其他方式运行该项目,请建议太多。 github文件的链接如下所示 https://github.com/PedroC

  • 我刚开始使用spring,我现在正在使用Spring4 一旦将war部署到JCS-SaaS(云)中,我将得到以下错误: org.springframework.beans.factory.XML.xmlBeanDefinitionStoreException:类路径资源[pepsiservlet-context.XML]的XML文档中的第33行无效;嵌套异常是org.xml.sax.SAXPars

  • 我对camunda和DMN一无所知。我试图在spring启动运行DMN示例。这里是我尝试在我的机器上运行的例子的链接。 这里是我的pom依赖项, 当我运行它时,它显示遵循stacktrace null 我没有得到的一件事是,在资源中,他们在xml文件中有决策模式,而在那里,他们有用于xsd的url,这是不起作用的。 经过一些;)的研究,我找到了这个链接,其中给出了xsd url,我试过了,但名称空