springfox

Swagger配置

匿名 (未验证) 提交于 2019-12-03 00:27:02
1、在pom.xml里面添加 <!-- swagger --> <dependency> <groupId> io.springfox </groupId> <artifactId> springfox-swagger2 </artifactId> <version> 2.2.2 </version> </dependency> <!-- swagger-ui --> <dependency> <groupId> io.springfox </groupId> <artifactId> springfox-swagger-ui </artifactId> <version> 2.2.2 </version> </dependency> 2、在Application文件同级添加Swagger2类 package com.boot.myspring ; import io.swagger.annotations. ApiOperation ; import org.springframework.context.annotation. Bean ; import org.springframework.context.annotation. Configuration ; import springfox.documentation.builders

Springfox与SpringMvc集成实现接口文档化

Deadly 提交于 2019-12-03 00:20:23
准备环境 一个web服务器(我使用的是tomcat、当然nginx都可以) eclipse开发环境使用SpringMvc框架的源码(我使用springfox官网提供的demo) 下载swagger-ui源码 实现目的 eclipse中启动后台项目(也可以直接打包war在另一个tomcat中发布) web服务器使用swagger-ui做为前端展示层展示后台基于swagger暴露的接口 后台服务支持跨域请求(项目上线可以关闭) 1. 后台接口演示环境搭建 1.1 项目pom文件对依赖包引用如下: <properties> <jackson2.version>2.5.1</jackson2.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring.version>4.2.6.RELEASE</spring.version> <!-- swagger --> <swagger.version>2.6.1</swagger.version> </properties> <dependencies> <!-- servlet Start --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet

Swagger保姆级教学

匿名 (未验证) 提交于 2019-12-03 00:13:02
Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法,参数和模型紧密集成到服务器端的代码,允许API来始终保持同步。 1.新建一个springboot项目 2.导入maven依赖(swagger2和swagger UI) <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId> io.springfox </groupId> <artifactId> springfox-swagger2 </artifactId> <version> 2.9.2 </version> </dependency> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependency> <groupId> io.springfox </groupId> <artifactId> springfox-swagger-ui </artifactId> <version> 2.9.2 </version> </dependency> 3

SwaggerConfig

匿名 (未验证) 提交于 2019-12-02 23:49:02
package me.zhengjie.common.swagger2; import com.google.common.base.Predicates; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ParameterBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.schema.ModelRef; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Parameter; import springfox.documentation

自定义枚举 --- Swagger文档展示

匿名 (未验证) 提交于 2019-12-02 23:43:01
在其它两篇文章中,已经解决的自定义枚举在MyBatis以及Rest接口的转换,但是在Springfox中还存在问题,不能使用code来作为api。本文通过扩展Springfox,实现了对自定义枚举的良好支持。 ps: 枚举的定义参见 自定义枚举 --- MyBatis字段映射 当前 Springfox默认枚举 存在2个问题 类型显示为string,需要修改为integer 枚举的类型显示为枚举值,需要修改为枚举的code值( CodedEnum 的定义请参见其他文章) 扩展后 扩展Springfox后的枚举展示 实现方式 实现 ModelPropertyBuilderPlugin 接口, @Component public class CodedEnumPropertyPlugin implements ModelPropertyBuilderPlugin { @Override public void apply(ModelPropertyContext context) { Optional<ApiModelProperty> annotation = Optional.absent(); if (context.getAnnotatedElement().isPresent()) { annotation = annotation.or(ApiModelProperties

配置 Swagger2 接口文档引擎

匿名 (未验证) 提交于 2019-12-02 23:40:02
文章目录 手写文档存在的问题 使用 Swagger 解决问题 Maven 配置 Swagger2 启用 Swagger2 使用 Swagger2 Swagger 注解说明 访问 Swagger2 手写文档存在的问题 文档需要更新的时候,需要再次发送一份给前端,也就是文档更新交流不及时。 接口返回结果不明确 不能直接在线测试接口,通常需要使用工具,比如:Postman 接口文档太多,不好管理 使用 Swagger 解决问题 Swagger 也就是为了解决这个问题,当然也不能说 Swagger 就一定是完美的,当然也有缺点,最明显的就是代码植入性比较强 Maven 增加 Swagger2 所需依赖, pom.xml 配置如下: < ! -- Swagger2 Begin -- > < dependency > < groupId > io . springfox < / groupId > < artifactId > springfox - swagger2 < / artifactId > < version > 2.8 .0 < / version > < / dependency > < dependency > < groupId > io . springfox < / groupId > < artifactId > springfox - swagger - ui <

Swagger 教程

匿名 (未验证) 提交于 2019-12-02 22:59:29
(一)Swagger和SpringFox 最受欢迎的API文档规范之一是OpenApi,以前称为Swagger。它允许您使用JSON或YAML元数据描述API的属性。它还提供了一个Web UI,它可以将元数据转换为一个很好的HTML文档。此外,通过该UI,您不仅可以浏览有关API端点的信息,还可以将UI用作REST客户端 - 您可以调用任何端点,指定要发送的数据并检查响应。它非常方便。 然而,手动编写此类文档并在代码更改时保持更新是不现实的。这就是SpringFox发挥作用的地方。它是Spring Framework的Swagger集成。它可以自动检查您的类,检测控制器,它们的方法,它们使用的模型类以及它们映射到的URL。没有任何手写文档,只需检查应用程序中的类,它就可以生成大量有关API的信息。多么酷啊?最重要的是,每当您进行更改时,它们都会反映在文档中。 (二)开始项目 首先,你需要一个带有一些Rest Controller的Spring Boot应用程序,我在 这里 准备了一个简单的。 在本文中,我使用了SpringFox 2.9.2和Spring Boot 1.5.10.RELEASE。它使用Swagger规范的第2版。版本3已经发布,但尚未(截至2014年2月)SpringFox支持。支持应在 下一版本中提供 。 使用本博文中描述的所有功能构建的最终项目的源代码可在

swagger配置

匿名 (未验证) 提交于 2019-12-02 21:53:32
Swagger作用: 自动生成javaAPI,避免开发过程中接口文档更新不及时。 Swagger 一.导入依赖: 导入依赖 <!--swagger包--><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.2.2</version></dependency><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.2.2</version></dependency><!--swagger包结束--> Swagger 二.Swagger首页的配置: 创建一个SwaggerConfig类,通过@Configuration托管给spring,然后通过@EnableSwagger2 注解开启Swagger,Config类大部分都是固定的,没什么改变的需要: 代码: package com.zy100.config;import org.springframework.context.annotation.Bean;import org.springframework.context

swagger报java.lang.NumberFormatException

匿名 (未验证) 提交于 2019-12-02 21:35:18
原因: 在使用@ApiModelProperty的时候有个example属性,如果没设置默认值,会自动赋值""空字符串,导致整型数据赋值有问题 解决办法: 修改maven依赖: <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> <exclusions> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> </exclusion> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> <version>1.5.22</version> </dependency> <dependency> <groupId>io.swagger<

Spring boot的Gradle配置

白昼怎懂夜的黑 提交于 2019-12-02 20:55:07
问题 最近尝试把自己现有的Maven工程转到Gradle工程上面来。 build.gradle buildscript { ext { springBootVersion = "2.1.0.RELEASE" } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'idea' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group "com.hngytobacco" version "1.0-SNAPSHOT" compileJava.options.encoding = "UTF-8" compileTestJava.options.encoding = "UTF-8" allprojects{ sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion