【问题标题】:'Correct the classpath of your application' in a Springboot Configuration in IntelliJIntelliJ 的 Spring Boot 配置中的“更正应用程序的类路径”
【发布时间】:2020-11-25 01:30:00
【问题描述】:

我有一个带有 IntelliJ-Idea IDE 的应用程序,它的 Springboot 配置出错并给出以下建议:

The following method did not exist:

org.springframework.context.ConfigurableApplicationContext.setApplicationStartup(Lorg/springframework/core/metrics/ApplicationStartup;)V

The method's class, org.springframework.context.ConfigurableApplicationContext, is available from the following locations:

jar:file:/C:/Users/tlmitch/.m2/repository/org/springframework/spring-context/5.2.8.RELEASE/spring-context-5.2.8.RELEASE.jar!/org/springframework/context/ConfigurableApplicationContext.class

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.context.ConfigurableApplicationContext

我对 IntelliJ-Idea 和 Springboot 比较陌生。如果这是说 Eclipse - 我可能只是去 Java 构建路径并添加包含该类的 jar 文件。

我对 IntelliJ 不太熟悉。到目前为止,如果缺少某些东西,我一直在运行“npm install”,这通常会解决它。

有什么建议吗?

非常感谢

【问题讨论】:

  • 您的错误提到 .m2 - 这向我暗示了 Maven。如果您的 pom.xml 调用 spring-boot-starter-parent 它会将 Spring JAR 带入项目。如果您不使用 Maven,则应该这样做。如果不能,则应将 JAR 添加到 /lib 文件中,并将所有这些 JAR 添加到项目配置中的 CLASSPATH 中。坚持使用 IntelliJ - 它比 Eclipse 更好。
  • 谢谢 - 我很感激。是的,我正在使用 Maven。 pom.xml 文件中没有任何类型的父标记。关于更正类路径 - 我可以看到 spring-context-5.2.8.RELEASE 库在依赖项中列出的位置。我只是不确定如何解决这个问题。
  • 找到父级并使用它。您应该使用 Soring Boot,而不是原始的 Soring。

标签: java spring-boot intellij-idea


【解决方案1】:

如果您在 pom.xml 文件中添加了 Spring 依赖项,它们可能与项目目录中 lib 文件夹中的 Spring 依赖项冲突。删除 lib 文件夹将解决此问题。 (只需确保您的项目在删除之前不依赖 lib 文件夹中的其他库)。

【讨论】:

    【解决方案2】:

    如错误提示:

    Correct the classpath of your application so that it contains a single, compatible version of org.springframework.context.ConfigurableApplicationContext
    

    你需要确保你的类路径只包含一个这样的类。您可以使用导航 |类动作查看项目中是否存在该类的多个版本,并排除Mavenpom.xml文件中的重复库依赖。

    【讨论】:

    • 我对 pom.xml 文件有点缺乏经验;我无法将类的多个版本映射到 pom.xml 文件的内容。如果我执行 cntrl-shift-n 然后查找 ConfigurableApplicationContext 类的实例 - 它会返回 8 个单独的实例。例如,它表示 ConfigurableApplicationContext 在包 org.springframework.context 的一个 5.2.8.RELEASE 和一个 5.2.10.RELEASE 中。我相信我理解 pom 文件中的 - 但我在 pom.xml 文件中找不到任何实例 org.springframework.context 来排除其中一个版本。
    猜你喜欢
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 2016-11-24
    • 2020-05-30
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多