问题描述
我正在尝试将 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>
另外,我添加了配置类:
@Configuration
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
当我运行我的项目时,我得到:
解决方法
我从 pom.xml 中删除了以下依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
对我来说它有效