【问题标题】:Problems compiling spring data mongodb repository definition编译spring数据mongodb存储库定义的问题
【发布时间】:2014-03-01 07:57:14
【问题描述】:

我有一个 spring servlet-context.xml 文件,其中包含以下定义:

...
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
....
<mongo:repositories base-package="com.example.repositories.mongodb"/>

这会导致 STS 中的编译错误:

描述资源路径位置类型处理 XML 时发生错误 '试图访问方法 org.springframework.context.annotation.AnnotationConfigUtils.processCommonDefinitionAnnotations(Lorg/springframework/beans/factory/annotation/AnnotatedBeanDefinition;)V 从班级 org.springframework.data.repository.config.RepositoryComponentProvider'。 有关更多信息,请参阅错误日志 详细信息 servlet-context.xml /example/src/main/webapp/WEB-INF 行 97 Spring Beans问题

当我删除 base-package 的内容时,错误消失了。我认为也许我定义的某些存储库是错误的,但它们似乎工作正常。该应用程序启动良好并且运行良好。我正在使用 spring-data-mongodb 1.4.0

有什么想法吗?

【问题讨论】:

  • servlet-context.xml 第 97 行的内容
  • 第 97 行 - mongo:repositories 定义
  • 我也有同样的问题。它仅显示在 IDE 中,在您运行 Web 应用程序时不会显示。忽略它是安全的。我认为它与这个jar“org.springframework.context_4.0.0.20130829-M3”有关,它可能会在下一个spring ide/sts版本中修复。

标签: xml spring spring-data spring-data-mongodb


【解决方案1】:

已通过 STS 3.5.0 解决。 STS 3.5.0 附带 Spring 4.0.2。

【讨论】:

    【解决方案2】:

    确保您使用的是最新的 Spring 版本。 Spring Data Mongo 1.4.0 需要 Spring 3.2.8:

    $ git checkout 1.4.0.RELEASE
    $ mvn dependency:list -Dsort
    …
    [INFO]    org.springframework.data:spring-data-commons:jar:1.7.0.RELEASE:compile
    [INFO]    org.springframework.data:spring-data-mongodb:jar:1.4.0.RELEASE:compile
    [INFO]    org.springframework:spring-aop:jar:3.2.8.RELEASE:compile
    [INFO]    org.springframework:spring-aspects:jar:3.2.8.RELEASE:compile
    [INFO]    org.springframework:spring-beans:jar:3.2.8.RELEASE:compile
    [INFO]    org.springframework:spring-context:jar:3.2.8.RELEASE:compile
    [INFO]    org.springframework:spring-core:jar:3.2.8.RELEASE:compile
    [INFO]    org.springframework:spring-expression:jar:3.2.8.RELEASE:compile
    [INFO]    org.springframework:spring-jdbc:jar:3.2.8.RELEASE:compile
    [INFO]    org.springframework:spring-orm:jar:3.2.8.RELEASE:compile
    [INFO]    org.springframework:spring-test:jar:3.2.8.RELEASE:test
    [INFO]    org.springframework:spring-tx:jar:3.2.8.RELEASE:compile
    

    特别是,我们依赖于从 Spring 3.2.5 IIRC 开始公开异常的方法。

    【讨论】:

    • 我使用的是spring 3.2.8
    【解决方案3】:

    我也遇到过类似的情况,我也有这个帖子(Setting up spring app with spring data repositories and mongo db)。我正在使用 spring 4.0.1 jar 和 Spring Data Mongo 1.4.0 jar,但我仍然看到这个问题。在您提到 mongo:repository 标记的地方会显示错误。你不会得到任何线索为什么它会发生。最后,我将 spring jar 版本更改为 4.0.0,然后从 maven 存储库中删除了所有 spring jar,并尝试(首先更新 maven)再次构建..它起作用了。我很确定它也适用于 4.0.1 spring jars。(我有另一个具有相同配置的项目,它在 4.0.1 jars 中运行良好:))我将此问题贡献给行家和日食。一些我完全不知道的问题

    如果您按照 Oliver 的建议使用正确的 jar 集,那么您需要进行一些试验和错误:)

    【讨论】:

    • 我尝试清除 maven repo,但没有成功。我正在使用弹簧 3.2.8
    【解决方案4】:

    我使用的是 spring 4.0.2,直到昨天一切正常。今天,当我将 spring-data-mongodb 从 1.3.4 更新到 1.4.0 时,我开始收到此错误。 1.4.0 与 spring 4.0.2 不兼容吗?我检查了我的 maven 依赖图,所有 spring jar 都指向 4.0.2

    [更新]这些错误在我升级到 STS 3.5.1 后消失了

    【讨论】:

      猜你喜欢
      • 2018-04-02
      • 2018-06-05
      • 2020-12-23
      • 2015-08-17
      • 2017-02-09
      • 2013-05-18
      • 1970-01-01
      • 1970-01-01
      • 2017-08-17
      相关资源
      最近更新 更多