Swagger文档(OpenAPI规范)通常需要通过代码中的注解生成(如Spring Boot项目),而非直接“查看”某个固定路径的文件。需先完成以下步骤:
springfox-swagger2、springfox-swagger-ui);SwaggerConfig),指定扫描的包路径和文档基本信息;@Api、@ApiOperation等注解,描述API细节;/v2/api-docs)。Swagger UI是可视化工具,用于交互式查看和测试API文档。在CentOS上,可通过以下两种方式访问:
mkdir -p /opt/swagger
cd /opt/swagger
wget https://github.com/swagger-api/swagger-ui/archive/v3.34.0.tar.gz
tar -xf v3.34.0.tar.gz
cd swagger-ui-3.34.0
dist目录内容复制到Web服务器目录(如Apache的/var/www/html/swagger-ui或Nginx的/usr/share/nginx/html/swagger-ui);index.html,将默认的Swagger JSON URL(如https://petstore.swagger.io/v2/swagger.json)替换为你的项目文档路径(如/v2/api-docs);sudo systemctl start httpd
sudo systemctl enable httpd
http://your-server-ip/swagger-ui/index.html)。若项目是基于Spring Boot开发的,可直接通过项目内置的Swagger UI访问:
SwaggerConfig类中启用了Swagger UI(如@EnableSwagger2);http://localhost:8080/swagger-ui.html(若项目部署在CentOS服务器上,需将localhost替换为服务器IP)。/api),需修改Swagger UI配置中的basePath,确保文档路径正确;通过以上步骤,你可以在CentOS系统上成功查看和交互式测试Swagger文档。