整合Swagger
整合Swagger
依赖导入
<!-- 使用swagger --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency> <!-- swagger美化 --> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> <version>1.9.3</version> </dependency>
注意事项:spring版本2.6.0会报错,建议回滚到2.5.0版本。
配置Swagger
package com.cao.frs.configuration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; import java.util.ArrayList; @Configuration @EnableSwagger2 //开启swagger public class MySwaggerConfig{ @Bean //创建swagger Bean实例 public Docket docker(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("财务系统") //组名 .select() .apis(RequestHandlerSelectors.basePackage("com.cao.frs.controller"))//扫描控制器路径 .paths(PathSelectors.any()) //过滤 .build(); } private ApiInfo apiInfo(){ Contact contact = new Contact("曹佳铭", "https://www.cnblogs.com/benbicao/", "17621778372@163.com"); return new ApiInfo("财务管理系统", "后台接口", "1.0", "https://www.cnblogs.com/benbicao/", contact, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList()); } }
使用Swagger
实体类注解@ApiModel
实体类属性@ApiModelProperty
控制器注解@Api
控制器方法注解@ApiOperation
推荐这些文章:
一、Swagger2介绍
前后端分离开发模式中,api文档是最好的沟通方式。
Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。
及时性 (接口变更后,能够及时准确地通知相关前后端开发人员)
规范性 (并且保证接口的规范性,如接口的地址,请求方式,参数及响应...
1.导包
<!--丝袜哥 共三个包,这里用的3.0版本-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-...
Swagger整合Jwt授权配置
欢迎关注博主公众号「Java大师」, 专注于分享Java领域干货文章http://www.javaman.cn/sb2/swagger-jwt
一、Swagger入门
1、什么是Swagger
Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务...
整合swagger进行模块测试
注意事项:为方便SpringBoot更好的整合Swagger,需要专门放置在一个模块中(maven子工程)
创建公共模块,整合swagger,为了所有模块进行使用
common/pom.xml,导入相关的依赖<dependencies>
<dependency>...
一、引入包,pom.XML配置如下
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
...
1、创建父工程
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
...
Springcloud gateway整合(集成)swagger2+finfe4j踩坑
项目使用gateway代替之前的zuul网关,需要整合swagger,踩了许多坑之后终于解决问题,话不多说直接上代码
因为使用的是阿里的东西所有注册中心选择了nacos,它的配置这里就不贴了
springcloud和boot版本依赖,这是父工程的配置
<properties>
<spring-boot.vers...
springcloud zuul网关整合swagger2,swagger被拦截问题
首先感谢一位博主的分享https://www.cnblogs.com/xiaohouzai/p/8886671.html
话不多说直接上图和代码
首先我们要有一个springcloud分布式项目
我就简单的一个eureka注册中心然后就是一个user用户然后当然就是zuul网关拉。
eureka的配置我就不多说了,我直接贴...
因为swagger版本与knife4j不兼容
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</a...
在使用Swagger2引入以下依赖后报错
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<...
文章链接:https://www.dianjilingqu.com/2121.html
本文章来源于网络,版权归原作者所有,如果本站文章侵犯了您的权益,请联系我们删除,联系邮箱:saisai#email.cn,感谢支持理解。