- 在pom.xml中引入swagger依赖包
- 在application.properties中添加配置
配置内容参考如下:
# swagger配置
swagger.title=对外开放接口API文档
swagger.description=HTTP对外开放接口
swagger.version=1.0.0
swagger.license=Apache License, Version 2.0
swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html
swagger.termsOfServiceUrl=https://github.com/dyc87112/spring-boot-starter-swagger
配置内容说明如下:
- swagger.enabled=是否启用swagger,默认:true
- swagger.title=标题
- swagger.description=描述
- swagger.version=版本
- swagger.license=许可证
- swagger.licenseUrl=许可证URL
- swagger.termsOfServiceUrl=服务条款URL
- swagger.contact.name=维护人
- swagger.contact.url=维护人URL
- swagger.contact.email=维护人email
- swagger.base-package=swagger扫描的基础包,默认:全扫描
- swagger.base-path=需要处理的基础URL规则,默认:/**
- swagger.exclude-path=需要排除的URL规则,默认:空
- swagger.host=文档的host信息,默认:空
- swagger.globalOperationParameters[0].name=参数名
- swagger.globalOperationParameters[0].description=描述信息
- swagger.globalOperationParameters[0].modelRef=指定参数类型
- swagger.globalOperationParameters[0].parameterType=指定参数存放位置,可选header,query,path,body.form
- swagger.globalOperationParameters[0].required=指定参数是否必传,true,false
详细配置可参考:https://github.com/SpringForAll/spring-boot-starter-swagger
- 配置拦截器
若项目有拦截器配置,需要在项目原有的拦截器配置中修改,忽略掉以下路径,以免被拦截导致无法访问。“swagger-ui.html”, “static/css/", "static/js/”, “swagger-resources”, “/**/error”, “v2/api-docs”
如: - 验证
完成配置后,在浏览器中打开url:http://{ip}:{port}/{project-name}/swagger-ui.html。出现如下页面说明配置成功
来源:CSDN
作者:小渣渣_
链接:https://blog.csdn.net/qq_36306640/article/details/104051468