更新版本到2.7.0时启动Springboot时出错“尝试调用不存在的方法”

Gab*_*ira 26 java maven spring-boot

我将Springboot版本更新到2.7.0,返回错误后:

\n

描述:

\n
An attempt was made to call a method that does not exist. The attempt was made from the following location:\n\n    org.webjars.WebJarAssetLocator.scanForWebJars(WebJarAssetLocator.java:183)\n\nThe following method did not exist:\n\n    \'io.github.classgraph.ClassGraph io.github.classgraph.ClassGraph.acceptPaths(java.lang.String[])\'\n\nThe calling method\'s class, org.webjars.WebJarAssetLocator, was loaded from the following location:\n\n    jar:file:/home/gabriel/.m2/repository/org/webjars/webjars-locator-core/0.50/webjars-locator-core-0.50.jar!/org/webjars/WebJarAssetLocator.class\n\nThe called method\'s class, io.github.classgraph.ClassGraph, is available from the following locations:\n\n    jar:file:/home/gabriel/.m2/repository/io/github/classgraph/classgraph/4.8.69/classgraph-4.8.69.jar!/io/github/classgraph/ClassGraph.class\n\nThe called method\'s class hierarchy was loaded from the following locations:\n\n    io.github.classgraph.ClassGraph: file:/home/gabriel/.m2/repository/io/github/classgraph/classgraph/4.8.69/classgraph-4.8.69.jar\n\n\nAction:\n\nCorrect the classpath of your application so that it contains compatible versions of the classes org.webjars.WebJarAssetLocator and io.github.classgraph.ClassGraph\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的 pom.xml

\n
An attempt was made to call a method that does not exist. The attempt was made from the following location:\n\n    org.webjars.WebJarAssetLocator.scanForWebJars(WebJarAssetLocator.java:183)\n\nThe following method did not exist:\n\n    \'io.github.classgraph.ClassGraph io.github.classgraph.ClassGraph.acceptPaths(java.lang.String[])\'\n\nThe calling method\'s class, org.webjars.WebJarAssetLocator, was loaded from the following location:\n\n    jar:file:/home/gabriel/.m2/repository/org/webjars/webjars-locator-core/0.50/webjars-locator-core-0.50.jar!/org/webjars/WebJarAssetLocator.class\n\nThe called method\'s class, io.github.classgraph.ClassGraph, is available from the following locations:\n\n    jar:file:/home/gabriel/.m2/repository/io/github/classgraph/classgraph/4.8.69/classgraph-4.8.69.jar!/io/github/classgraph/ClassGraph.class\n\nThe called method\'s class hierarchy was loaded from the following locations:\n\n    io.github.classgraph.ClassGraph: file:/home/gabriel/.m2/repository/io/github/classgraph/classgraph/4.8.69/classgraph-4.8.69.jar\n\n\nAction:\n\nCorrect the classpath of your application so that it contains compatible versions of the classes org.webjars.WebJarAssetLocator and io.github.classgraph.ClassGraph\n
Run Code Online (Sandbox Code Playgroud)\n

我可以解决这个问题吗?

\n

And*_*son 43

的传递依赖项不兼容org.springdoc:springdoc-openapi-ui。这取决于两者org.webjars:webjars-core-locatorio.github.classgraph:classgraph但它们的版本不兼容。

Spring Boot 的依赖管理webjars-core-locator使用 version 0.50webjars-core-locator 0.50默认情况下会使用classgraph 4.8.139,但由于 Maven 解决版本冲突的方式,它被降级为4.8.69.

您可以通过在现有的导入旁边4.8.139添加一些依赖项管理来恢复使用来解决该问题:pom.xmlspring-cloud-dependencies

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>io.github.classgraph</groupId>
            <artifactId>classgraph</artifactId>
            <version>4.8.139</version>
        </dependency>
    </dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)


小智 16

将以下实现添加到 build.gradle 文件也可以解决该问题:implementation('org.springdoc:springdoc-openapi-ui:1.6.9')


gla*_*ace 13

正如其他答案中所述,确实是 springdoc-openapi-ui 在这里制造麻烦。我遇到了有关 WebJarAssetLocator 和/或 ClassGraph 的各种错误,这些错误都通过更新 springdoc 解决了。

现在,有了 spring-boot 2.7.2 和 spring-doc 1.6.9,一切又恢复顺利了。

  • 似乎在 2.7.3 中又重新出现了。正如 @Andy Wilkinson 所建议的,将其解决方案的 io.github.classgraph 部分添加到 pom.xml 的依赖管理部分即可修复该问题。 (2认同)

小智 7

我已修复将 springdoc-openapi-ui 升级到 1.6.12