springfox

SpringBoot+Swagger整合API

非 Y 不嫁゛ 提交于 2020-04-26 07:37:37
SpringBoot+Swagger整合API Swagger:整合规范的api,有界面的操作,测试 1.在pom.xml加入swagger依赖 <!--整合Swagger2配置类--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> 2.在application.yml开启swagger #引入swagger swagger: enable: true    3.配置SwaggerConfiguration.java 注意:@Value("${swagger2.basePackage:com.spingcloud.serviceconsumer.controller}") 添加扫描的api入口 @Configuration @EnableSwagger2 public class SwaggerConfiguration

整合 springboot 和 swagger出问题

爱⌒轻易说出口 提交于 2020-04-24 17:03:10
整合 springboot 和 swagger ,出现报错, org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'apiDocumentationScanner' defined in URL [jar:file:/C:/Users/Code-X/.m2/repository/io/springfox/springfox-spring-web/2.7.0/springfox-spring-web-2.7.0.jar!/springfox/documentation/spring/web/scanners/ApiDocumentationScanner. class ]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'apiListingScanner' defined in URL [jar:file:/C:/Users

How to change basePath for Springfox Swagger 2.0

牧云@^-^@ 提交于 2020-04-07 17:37:44
问题 I'm running a service, where Swagger UI is accessible at: http://serviceURL/swagger-ui.html However, it is behind a proxy, such as: http://proxyURL/serviceName Generated URLs by Swagger UI are looking like: http://proxyURL/ instead of the actual URL with the serviceName as suffix. As far as I get it, this means manipulating the basePath property. As per documentation: A swagger API documentation can no longer describe operations on different base paths. In 1.2 and earlier, each resource could

集成 Swagger2 构建强大的 RESTful API 文档

杀马特。学长 韩版系。学妹 提交于 2020-03-29 07:04:03
微信公众号:一个优秀的废人如有问题或建议,请后台留言,我会尽力解决你的问题。 前言 快过年了,不知道你们啥时候放年假,忙不忙。反正我是挺闲的,所以有时间写 blog。今天给你们带来 SpringBoot 集成 Swagger2 的教程。 什么是 Swagger2 Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。 为什么使用 Swagger2 ? 相信刚开始不熟悉 web 开发的时候,大家都有手写 Api 文档的时候。而手写 Api 文档主要有以下几个痛点: 文档需要更新的时候,需要再次发送一份给前端,也就是文档更新交流不及时。 接口返回结果不明确。 不能直接在线测试接口,通常需要使用工具,比如 postman。 接口文档太多,不好管理。 这些痛点在前后端分离的大型项目上显得尤为烦躁。而 Swagger2 的出现恰好能个解决这些痛点。因为 Swagger2 有以下功能: 文档自动更新,只要生成 Api 的网址没变,基本不需要跟前端沟通。 接口返回结果非常明确,包括数据类型,状态码,错误信息等。 可以直接在线测试文档,而且还有实例提供给你。 只需要一次配置便可使用,之后只要会有一份接口文档,非常易于管理。 集成演示 首先新建一个 SpringBoot 项目,还不会的参考我这篇旧文—— 如何使用 IDEA 构建 Spring

生产环境下springboot中配置禁用swagger

穿精又带淫゛_ 提交于 2020-03-18 15:56:54
某厂面试归来,发现自己落伍了!>>> 一、序言 在生产环境下,我们需要关闭swagger配置,避免暴露接口的这种危险行为。 二、方法: 禁用方法1:使用注解@Profile({"dev","test"}) 表示在开发或测试环境开启,而在生产关闭。(推荐使用) 禁用方法2:使用注解@ConditionalOnProperty(name = "swagger.enable", havingValue = "true") 然后在测试配置或者开发配置中 添加 swagger.enable = true 即可开启,生产环境不填则默认关闭Swagger. 如方法1: package com.left; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import

springboot配置swagger

霸气de小男生 提交于 2020-03-17 13:44:23
某厂面试归来,发现自己落伍了!>>> 一、springboot配置swagger后自动生成文档 方便测试 二、集成步骤(假设springboot已经搭建完成 可运行) 2.1、引入pom文件 <!-- swagger --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.5.0</version> </dependency> <!-- swagger-ui --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.5.0</version> </dependency> 2.2、config类 package com.mao.swagger.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import io.swagger.annotations.ApiOperation; import

Springfox swagger not working in spring boot 2.2.0

给你一囗甜甜゛ 提交于 2020-03-17 10:39:49
问题 I want to upgrade spring boot v2.1.9 to 2.2.0. But after the upgrade I am getting some exceptions, which says spring fox is using an older version of spring-plugin-core. Is there any alternate solution for this or do I need to give up the springfox plugin? *************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: springfox.documentation.spring.web

springmvc4集成swagger2

我是研究僧i 提交于 2020-03-08 03:44:50
首先在原有的springmvc工程的pom文件中增加swagger <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> 增加swagger的配置类 package com.founder.fwpt.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import springfox.documentation.builders.ApiInfoBuilder; import springfox

7.3 Swagger

穿精又带淫゛_ 提交于 2020-03-06 03:23:13
一.学习目标 了解Swagger的作用和概念 了解前后端分离 在SpringBoot中集成Swagger 二.Swagger简介 号称世界上最流行的API框架 RestFul API文档在线自动生成工具 => API文档与API定义同步更新 直接运行,可以在线测试API接口 支持多种语言:(Java,PHP......) 1.官网:https://swagger.io 2.在项目中使用Swagger需要springfox (1)springfox swagger2 (2)springfox swagger UI 三.SpringBoot集成Swagger 1.步骤: 建立一个Springboot带Spring MVC的项目 导入两个依赖swagger2和swaggerUI 编写一个HelloController测试项目是否可以正常运行(略) 编写config配置Swagger 测试运行 2.新建SpringBoot的web项目 3.导入两个依赖swagger2和swaggerUI <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io

SpringBoot实战:SpringBoot之Swagger集成

馋奶兔 提交于 2020-03-05 00:43:30
Swagger是什么? Swagger 是一个规范且完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。Swagger 的目标是对 REST API 定义一个标准且和语言无关的接口,可以让人和计算机拥有无须访问源码、文档或网络流量监测就可以发现和理解服务的能力。当通过 Swagger 进行正确定义,用户可以理解远程服务并使用最少实现逻辑与远程服务进行交互。与为底层编程所实现的接口类似,Swagger 消除了调用服务时可能会有的猜测。 Swagger 的优势有哪些 支持 API 自动生成同步的在线文档:使用 Swagger 后可以直接通过代码生成文档,不再需要自己手动编写接口文档了,对程序员来说非常方便,可以节约写文档的时间去学习新技术。 提供 Web 页面在线测试 API:光有文档还不够,Swagger 生成的文档还支持在线测试。参数和格式都定好了,直接在界面上输入参数对应的值即可在线测试接口。 SpringBoot集成Swagger很方便,接下来将演示如何集成 首先pom.xml引入相关依赖 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency>