1

在配置 Hibernate 时,我的配置文件中出现以下错误。

Referenced file contains errors (http://www.springframework.org/schema/beans/spring-beans-3.1.xsd)

当我检查“更多详细信息”时,它给了我以下信息:

sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'http://www.springframework.org/schema/beans,identifiedType'.

我有一个 applicationContext.xml 文件,其架构定义(我在其中导入 hibernate-context.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:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.1.xsd
            http://www.springframework.org/schema/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

..
..
<!-- Imports datasource configuration -->
<import resource="hibernate-context.xml" />

我的 hibernate-context.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:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx" 
    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:util="http://www.springframework.org/schema/util" 
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.1.xsd
            http://www.springframework.org/schema/jdbc 
            http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.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-3.1.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
            ">

正是在这个文件(hibernate-context.xml)中,我得到了错误。我的思想被吹走了,我被困住了....如何摆脱这个错误?请指导!!:(

4

3 回答 3

7

好的,问题解决了。我把它写在这里作为任何陷入同样愚蠢情况的人的未来参考。

我从 hibernate-context.xml 更改了这一行:

http://www.springframework.org/schema/data/jpa
            http://www.springframework.org/schema/data/jpa/spring-jpa.xsd

http://www.springframework.org/schema/data/jpa
            http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd

打败我为什么,但它解决了我得到的错误。

于 2013-02-22T18:45:22.440 回答
0

我对 Spring 4.2 有同样的问题

我修复了将 http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 更改
http://www.springframework.org/schema/data/jpa/spring-jpa-1.11.xsd 的问题

于 2021-01-12T08:06:16.993 回答
0

6 年后,我从 Spring 3.2 升级到 Spring 4.3 时遇到了同样的问题。

即使我使用的是 Spring Data 1.10,我还是通过更改为

http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.8.xsd

于 2019-04-04T09:12:52.270 回答