springBoot 整合swagger

1、pom.xml 配置

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>

2、swagger配置类

@Configuration
@EnableSwagger2
public class SwaggerConfig { @Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) //这里采用包含注解的方式来确定要显示的接口
.paths(PathSelectors.any())
.build();
} @SuppressWarnings("deprecation")
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("接口说明文档")
.description("app doc")
//.termsOfServiceUrl("http://xxxx")
.contact("")
.version("1.0")
.build();
} }

3、Application类

public class AppApplication  extends WebMvcConfigurerAdapter {

    @Value("${spring.swaggerOpenFlag}")
private boolean swaggerOpenFlag; /**
* 增加静态资源
* */
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if(swaggerOpenFlag){
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
public static void main(String[] args) {
SpringApplication.run(AppApplication.class, args);
} }

4、application.yml

spring:
profiles: dev
swaggerOpenFlag: true #是否开启swagger spring:
profiles: produce
swaggerOpenFlag: false #是否开启swagger

5、访问swagger

访问地址 http://localhost:8888/swagger-ui.html

SpringBoot 整合swagger的更多相关文章

  1. SpringBoot整合Swagger和Actuator

    前言 本篇文章主要介绍的是SpringBoot整合Swagger(API文档生成框架)和SpringBoot整合Actuator(项目监控)使用教程. SpringBoot整合Swagger 说明:如 ...

  2. 【SpringBoot | Swagger】SpringBoot整合Swagger

    SpringBoot整合Swagger 1. 什么是Swagger Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.简单说就是项目跑起来了, ...

  3. springboot整合swagger。完爆前后端调试

    web接口开发时在调试阶段最麻烦的就是参数调试,前端需要咨询后端.后端有时候自己也不是很了解.这时候就会造成调试一次接口就需要看一次代码.Swagger帮我们解决对接的麻烦 springboot接入s ...

  4. SpringBoot整合Swagger实战

    源码地址:https://github.com/laolunsi/spring-boot-examples 目前SpringBoot常被用于开发Java Web应用,特别是前后端分离项目.为方便前后端 ...

  5. SpringBoot整合Swagger测试api构建

    @Author:SimpleWu 什么是Swagger? Swagger是什么:THE WORLD'S MOST POPULAR API TOOLING 根据官网的介绍: Swagger Inspec ...

  6. SpringBoot整合swagger

    Swagger使用 Swagger有什么用? swagger是一个流行的API开发框架,这个框架以“开放API声明”(OpenAPI Specification,OAS)为基础, 对整个API的开发周 ...

  7. springboot入门系列(二):SpringBoot整合Swagger

    上一篇<简单搭建SpringBoot项目>讲了简单的搭建SpringBoot 项目,而 SpringBoot 和 Swagger-ui 搭配在持续交付的前后端开发中意义重大,Swagger ...

  8. SpringBoot整合Swagger初探

    当下的Web项目大都采用前后端分离+分布式微服务的架构.前后端分离式的开发中,前端开发人员要与后端开发人员协商通信接口,约定接口规范.因此对于开发人员来说能够维持一份及时更新且完整全面的API文档会大 ...

  9. SpringBoot整合Swagger框架 ,并设置接口请求头token默认值

      引入maven依赖 <!-- swagger2--> <dependency> <groupId>io.springfox</groupId> &l ...

随机推荐

  1. [Swift实际操作]八、实用进阶-(3)闭包在定时任务、动画和线程中的使用实际操作

    闭包的使用相当广泛,它是可以在代码中被传递和引用的具有独立功能的模块.双击打开之前创建的空白项目.本文将演示闭包在定时任务.动画和线程中的使用.在左侧的项目导航区,打开视图控制器的代码文件:ViewC ...

  2. delphi 10.2 ----简单的叠乘例子

    unit Unit11; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, Syste ...

  3. Spring中applicationContext.xml详解

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  4. 28.earch in Rotated Sorted Array(排序旋转数组中查找)

    Level:   Medium 题目描述: Suppose an array sorted in ascending order is rotated at some pivot unknown to ...

  5. shell-009:删除字母

    把一个文件里的前100行中有字母的行删除:再把101-200行的字母去掉 #!bin/bashsed '101.200s/[a-zA-Z]//g' filesed -n '1.100'p file | ...

  6. h5 页面点击添加添加input框

    h5 页面点击添加添加input框 前段时间有个需求,页面要能点击添加按钮控制input框的个数,当时感觉有点难,就没做,这两个又遇到了,没办法写了个简单的 效果图,加号增加,减号减少 直接上代码, ...

  7. Python 求“元组、列表、字典、数组和矩阵”的大小

    总结: 首先 import numpy as np A = np.random.randint(1,100,size = (4,5)) >>A>>array([[56, 96, ...

  8. poj3207 Ikki's Story IV - Panda's Trick 2-SAT

    题目传送门 题意:在一个圆上顺时针安放着n个点,给出m条线段连接端点,要求线段不相交,线段可以在圆内也可以在圆外,问是否可以. 思路:假设一条线段,放在圆外是A,放在园内是A',那么两条线段如果必须一 ...

  9. Java简易撞鬼游戏demo

    9*9方格内两点随机行走,相遇则停止. public class 撞鬼 { public static int length = 9; public static char[][] matrix = ...

  10. 查看Postgresql的连接状况

    今天遇到一个问题,就是pg一直报错,说有太多的客户端连接到数据库上面.但现在不知道是什么程序连接.pg默认的max_connection是100,我并没有修改过,以为平时公司内部用,应该够了,但现在貌 ...