【问题标题】:Spring data xml configuration schema validation errorSpring data xml配置模式验证错误
【发布时间】:2016-01-30 13:32:44
【问题描述】:

我有一个项目使用 Spring (context, transaction, aect) 4.1.6.RELEASE 和 spring-data-jpa 1.8.0.RELEASE 并遇到奇怪的错误,假设是由 xsd 验证引起的。但是,我无法找出原因。奇怪的是,项目运行良好,我所有的 bean 都被正确识别。

我正在使用 Eclipse luna 和 Spring Tools Suite 插件

我从 applicationContext.xml 中删除了所有内容,但会导致问题的“jpa:”行除外。 xml 是使用 STS 插件创建的。

我试图从 xsds 中删除版本号,但没有成功。

【问题讨论】:

    标签: xml eclipse spring spring-data


    【解决方案1】:

    我前段时间遇到过同样的问题,所有错误都是由jpa引起的 我将 jpa 配置移到了新的配置文件中

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:jpa="http://www.springframework.org/schema/data/jpa"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        default-destroy-method="destroy"
        xsi:schemaLocation="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-4.1.xsd
            http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.8.xsd">
    
        <context:component-scan base-package="com.some.validator" />
        <context:component-scan base-package="com.some.security.rest" />
        <jpa:repositories base-package="com.some.repository.path"
            entity-manager-factory-ref="entityManagerFactory" />
    </beans>
    

    一些 Maven 导入:

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.8.2.RELEASE</version>
        </dependency>
    

    和spring框架版本

        <org.springframework-version>4.1.7.RELEASE</org.springframework-version>
    

    尝试清理项目并使用 maven 更新它

    【讨论】:

    • 唯一对我有用的答案,虽然我发现这个解决方案并不令人满意......
    • 不同jpa版本存在一些兼容性问题
    【解决方案2】:

    为了解决这些 XML 验证问题,您可以尝试完全删除版本符号,如下所示,并让 Spring 加载通用模式位置。

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schem...ng-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/schem...spring-jpa.xsd
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
    

    包含通用或版本化的XSD 架构位置不会对应用程序行为产生不同的结果。此外,尝试重新组织您的 pom.xml 并确保使用正确的版本解决了临时依赖关系。

    这个解决方案的奇怪部分是它在少数应用程序中对我有用,但在我遇到相同错误的其他应用程序中却失败了。对我来说,有时将版本化的XSDs 更改为通用,然后再次将它们改回版本化已经解决了。 Eclipse Luna-tic 行为!

    PS:无意冒犯 Eclipse 爱好者。

    【讨论】:

      【解决方案3】:

      我和你有同样的问题,它来自 xsd 文件的版本。特别是,当我删除 spring Context XSD 版本时,问题就消失了。

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:context="http://www.springframework.org/schema/context"
      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/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/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.xsd">
      
      <jpa:repositories base-package="com.app.repositories" />
      </beans>
      

      该 XML 文件不会为我生成任何验证错误。

      干杯,

      伊曼纽尔

      【讨论】:

      • 您的 XML 仍然存在同样的问题:“描述资源路径位置类型引用的文件包含错误(project-aware://butler-sync/org/springframework/beans/factory/xml/spring-tool -4.1.xsd),位置第 1 行"
      猜你喜欢
      • 1970-01-01
      • 2020-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多