引起原因:java.lang.ClassNotFoundException:springfox.documentation.common.ClassPresentInClassPathCondition

Jac*_*ack 4 java swagger spring-boot springfox

我正在尝试将 Swagger 添加到我的项目https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api

我在上面的教程中得到了 4.3 段落,当我运行我的应用程序时,我遇到了一些错误。

我将其添加到我的pom.xml

    <dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
  <version>2.9.2</version>
</dependency>

<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-boot-starter</artifactId>
  <version>3.0.0</version>
</dependency>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.4.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

另外,我添加了配置类:

@Configuration
public class SwaggerConfig {
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build();
}
}
Run Code Online (Sandbox Code Playgroud)

当我运行我的项目时,我得到:

堆栈跟踪1 堆栈跟踪2

小智 7

我从 pom.xml 中删除了以下依赖项

<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-boot-starter</artifactId>
  <version>3.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

对我来说它有效

  • 这会删除 Swagger 页面,这可能不是您想要的。 (4认同)