SpringBoot 显示Swagger Api 文档

1.  配置pom文件,在pom文件中引入Swagger的相关依赖:

 

<!-- swagger -->
<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>swagger-bootstrap-ui</artifactId>
    <version>1.9.3</version>
</dependency>

<dependency>
    <groupId>com.spring4all</groupId>
    <artifactId>swagger-spring-boot-starter</artifactId>
    <version>1.9.0.RELEASE</version>
</dependency>

2.在application.yml 文件中配置相关 swagger 参数

   2-1. 配置说明--默认配置:

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信息,默认:空

     2-2. Authorization 鉴权配置

# 鉴权策略ID,对应 SecurityReferences ID
swagger.authorization.name=Authorization

# 鉴权策略,可选 ApiKey | BasicAuth | None,默认ApiKey
swagger.authorization.type=ApiKey

# 鉴权传递的Header参数
swagger.authorization.key-name=token

# 鉴权传递的Header参数名称
swagger.authorization.name=token

# 需要开启鉴权URL的正则, 默认^.*$匹配所有URL
swagger.authorization.auth-regex=^.*$

说明:其他具体的 参数配置 :https://github.com/SpringForAll/spring-boot-starter-swagger

 

3.在项目启动入口添加注解 @EnableSwagger2Doc

import com.spring4all.swagger.EnableSwagger2Doc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@EnableSwagger2Doc
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

 

4.启动项目访问地址 :http://localhost:8005/doc.html,内容如下:

 

 

 

swagger demo地址:https://github.com/abbottyf/swagger

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值