spring data - jpa application-context schema错误

时间:2014-06-09 04:29:16

标签: spring jpa spring-data

我遇到了spring jpa存储库的xml架构问题。

我已尝试过在线提供的所有建议,但似乎无法解决。

请帮忙。

在存储库的application-context.xml中收到此错误。

Multiple annotations found at this line:
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'repository:repositories'.
- cvc-complex-type.2.4.a: Invalid content was found starting with element 'repositories'. One of '{"http://www.springframework.org/schema/
beans":import, "http://www.springframework.org/schema/beans":alias, "http://www.springframework.org/schema/beans":bean, WC[##other:"http://
www.springframework.org/schema/beans"]}' is expected.

我的应用程序上下文如下所示

<?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:tx="http://www.springframework.org/schema/tx"
    xmlns:repository="http://www.springframework.org/schema/data/repository"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
        http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.7.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <jdbc:embedded-database id="dataSource" type="H2" />

    <tx:annotation-driven transaction-manager="transactionManager" />

    <repositories base-package="com.company.repositories" />

    <context:component-scan base-package="com.company.*" />
</beans>

2 个答案:

答案 0 :(得分:1)

我们通常建议您参考不具备版本号的架构文件,因为这样可以确保您从类路径中选择依赖版本。

原因是XSD并不知道任何类型的版本概念。这意味着spring-beans.xsdspring-beans-3.0.xsd与XSD完全无关,这反过来意味着如果您碰巧导入它们(我会在一秒钟内完成此操作),这将产生错误因为XSD认为它们中声明的类型要声明两次。

您可能会意外导入非版本化XSD的原因是Spring Data XSD实际上是指它们以确保我们选择最新版本(为了向前兼容)。

长话短说:从名称中删除显式版本,你应该很好。

答案 1 :(得分:0)

经过大量的试验和错误后,以下应用程序上下文似乎没有任何错误。

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

    <jdbc:embedded-database id="dataSource" type="H2" />

    <tx:annotation-driven transaction-manager="transactionManager" />

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

    <context:component-scan base-package="com.company.*" />
</beans>

在我之前尝试它时,为什么它没有解决错误。

我收到了以下错误。

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

我做了以下,首选项&gt;一般&gt; <网络连接>缓存 - &gt;删除了缓存xsd。

然后我点击了问题视图并删除了问题并清理了项目。现在没有错误。任何了解这一点的人都欢迎回答。