springfox

springboot集成swagger2

点点圈 提交于 2019-11-27 00:55:48
pom.xml <?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>cn.ffcs.tsp</groupId> <artifactId>springboot</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>cn.ffcs.tsp.msa</groupId> <artifactId>springbootSwagger</artifactId> <version>1.0.0-SNAPSHOT</version> <name>springbootSwagger</name> <url>http://maven.apache.org</url> <properties> <project.build

SpringBoot 通过配置禁用swagger

依然范特西╮ 提交于 2019-11-26 23:08:15
转自: https://blog.csdn.net/weixin_37264997/article/details/82762050 一、序言 在生产环境下,我们需要关闭swagger配置,避免暴露接口的这种危险行为。 二、方法: 禁用方法1: 使用注解 @Value() 推荐使用 1 package com.dc.config; 2 3 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 4 import org.springframework.context.annotation.Bean; 5 import org.springframework.context.annotation.Configuration; 6 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 7 import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 8 import org.springframework.web.servlet.config.annotation

springboot配置swagger

大城市里の小女人 提交于 2019-11-26 23:07:38
1,添加配置类 @Configuration @EnableSwagger2 @Profile({"default", "dev-online", "test"}) public class SwaggerConfiguration { @Bean public Docket appDoc() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(appApiInfo()) .directModelSubstitute(Date.class, Double.class) .directModelSubstitute(LocalDate.class, Double.class) .select() .apis(RequestHandlerSelectors.basePackage("com.example.multidatasource.web"))//换成对应应用入口层级 .paths(PathSelectors.any()) .build(); } private ApiInfo appApiInfo() { return new ApiInfoBuilder() .title("plan-warehousing 接口文档") .version("1.0.0") .build(); } } 2,添加pom文件 <!-

How to configure Spring Security to allow Swagger URL to be accessed without authentication

佐手、 提交于 2019-11-26 22:31:15
问题 My project has Spring Security. Main issue: Not able to access swagger URL at http://localhost:8080/api/v2/api-docs. It says Missing or invalid Authorization header. Screenshot of the browser window My pom.xml has the following entries <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>

SpringBoot——SpringBoot整合Swagger

百般思念 提交于 2019-11-26 20:38:24
1.添加pom依赖 向pom文件中添加依赖 <!-- swagger --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency> <!-- swagger-ui --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>1.5.10</version> <scope>compile</scope> </dependency> 2.添加Swagger的配置类 代码如下: package com.youyou.config; import org.springframework.context.annotation.Bean; import org.springframework

Spring Boot 系列(七)Swagger2-生成RESTful接口文档

╄→尐↘猪︶ㄣ 提交于 2019-11-26 17:03:40
Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法,参数和模型紧密集成到服务器端的代码,允许API来始终保持同步。 开始 1、pom.xml 添加依赖: <!-- swagger RESTful API 文档 --> <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> 2、创建 User 实体 package com.sam.demo.domain; /** * @author sam * @since 2017/7/17 */ public class User { private Long id; private String name; private int age; //getter &

Spring集成Swagger,Java自动生成Api文档

妖精的绣舞 提交于 2019-11-26 17:03:31
博主很懒... Swagger官网: http://swagger.io GitHub地址: https://github.com/swagger-api 官方注解文档: http://docs.swagger.io/swagger-core/apidocs/index.html Swagger-UI地址: https://github.com/swagger-api/swagger-ui swagger最终效果图 好,开始说Spring怎么配置Swagger了 1.pom.xml引入需要的jar包 <!-- 构建Restful API 我这版本是2.6.1 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${swagger2.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger2.version}</version> </dependency> 2.扫描你的Swagger2config

Remove Basic Error Controller In SpringFox SwaggerUI

霸气de小男生 提交于 2019-11-26 16:58:52
问题 Is there a way i can remove the "basic-error-controller" from springfox swagger-ui? Picture: 回答1: You can restrict the request handler selector to scan only the package of your project: return new Docket( DocumentationType.SWAGGER_2) .select() .apis( RequestHandlerSelectors.basePackage( "your package" ) ) ... 回答2: I think, the most elegant solution is to include only @RestController controllers into swagger, only thing to bear in mind, is to annotate all the REST controllers with that

AdminSwagger2Configuration

纵然是瞬间 提交于 2019-11-26 11:06:21
package org.linlinjava.litemall.admin.config; 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 springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * swagger在线文档配置<br> * 项目启动后可通过地址

springboot+swagger接口文档企业实践(上)

梦想与她 提交于 2019-11-26 10:14:46
tags: springboot swagger doc 一句话概括:对于产品开发,特别是前后端分离的开发模式,接口文档是连接前后端的枢纽,本文对springboot+swagger在企业的实践进行详细描述。 1.引言 在软件开发过程中,接口设计与接口文档编写是重要的一环,特别是在前后端分离的情况下,接口说明文档是开发人员之间的连接点。接口文档的编写有很多方式,可以使用word,也可以使用编写工具如小幺鸡,这些基本属于脱离代码编写的文档,如果接口变化,需要额外修改文档,增加工作量。如何提高写接口文档效率,在springboot开发中,结合swagger来提供接口文档说明是一个很好的实践,通过配置与注解,在编写接口代码过程中,同时也把接口文档写好,接口需要变更时,文档也同时变更,具有工作量少,效率高,接口文档直观简洁,可实时调用验证等好处。本文基本springboot2+swagger2,结合在企业中的实践,对接口文档的编写进行详细说明,具体有如下内容: swagger介绍及文档生成说明 使用springboot2+swagger2构建示例工程及配置描述 使用注解添加文档内容说明 使用全局参数进行接口认证 如需看源码,本文 示例工程地址 : https://github.com/mianshenglee/my-example 2.swagger简介 2.1 swagger 介绍