在Debian系统上集成Swagger(现称为OpenAPI Specification)与Spring Boot的步骤如下:
sudo apt update
sudo apt install openjdk-11-jdk maven
使用Spring Initializr创建一个新的Spring Boot项目,并下载到本地。
将下载的项目解压到一个目录中,并使用你喜欢的IDE(如IntelliJ IDEA或Eclipse)导入该项目。
在项目的pom.xml
文件中添加Swagger依赖。
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
创建一个配置类来配置Swagger。
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage(com.yourpackage))
.paths(PathSelectors.any())
.build();
}
}
在IDE中运行Spring Boot应用,或者在终端中使用以下命令启动:
mvn spring-boot:run
启动应用后,打开浏览器并访问以下URL:
http://localhost:8080/swagger-ui.html
你应该能够看到Swagger UI界面,其中列出了你的API文档。
通过以上步骤,你就可以在Debian系统中成功集成Swagger与Spring Boot,并使用Swagger UI来查看和测试你的API文档。