SpringBoot 配置 Swagger
Profile Config 多环境不同配置
1.添加 Pom 文件
<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. 添加配置类 SwaggerConfig.java
package com.vipsoft.web.boot.config; import springfox.documentation.service.Contact;
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; @Configuration
@EnableSwagger2
@Profile({"dev","test"}) //根据环境配置是否启用
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.basePackage("com.vipsoft.model.user.controller"))
.paths(PathSelectors.any())
.build().apiInfo(apiInfo());
} //构建 api文档的详细信息函数,注意这里的注解引用的是哪个
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("SpringBoot整合Swagger")
.description("SpringBoot整合Swagger,API接口描述......")
.version("9.0")
.contact(new Contact("VipSoft","www.vipsoft.com.cn","47262947@qq.com"))
.license("The Apache License")
.licenseUrl("http://www.baidu.com")
.build();
}
}

3. 添加接口说明
需要暴露出去的实体
/**
* 用户实体
*/
@ApiModel
public class Users {
@ApiModelProperty(value = "用户id")
private String Id; @ApiModelProperty(value = "用户名")
private String userName; @ApiModelProperty(value = "密码")
private String password; @ApiModelProperty(value = "真实姓名")
private String realName; private Date createTime;
。。。。。
}
Controller
@Api(description = "用户操作接口")
@RestController
@RequestMapping("/user")
public class UserController { Logger logger = LoggerFactory.getLogger(UserController.class);
Logger loggerApiHis = LoggerFactory.getLogger("apiHis"); //apiHis 对应 logback.xml中的配置 /**
* Mybatis 获取 List 列表
*
* @param request
* @return
*/ @ApiOperation(value = "获取用户信息", notes = "这边可以不写")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "主健", defaultValue = "深圳", required = true)
})
@GetMapping(value = "/get/{id}")
public Users get(HttpServletRequest request, @PathVariable("id") String id) {
return userService.get(id);
}

启动类上加@EnableSwagger2 否则会报 Swagger2 Unable to infer base url. This is common (降低版本好像也可以没试过)

输入访问地址:http://localhost:8080/swagger-ui.htm

SpringBoot 配置 Swagger的更多相关文章
- SpringBoot配置Swagger实例(POST接收json参数)
工程目录结构: 首先,引入jar包,只需要以下两个即可 <dependency> <groupId>io.springfox</groupId> <artif ...
- springboot配置swagger
1,添加配置类 @Configuration @EnableSwagger2 @Profile({"default", "dev-online", " ...
- springboot 集成swagger ui
springboot 配置swagger ui 1. 添加依赖 <!-- swagger ui --> <dependency> <groupId>io.sprin ...
- 整合 springboot 和 swagger出问题
整合 springboot 和 swagger ,出现报错, org.springframework.beans.factory.UnsatisfiedDependencyException: Err ...
- SpringBoot集成Swagger接口管理工具
手写Api文档的几个痛点: 文档需要更新的时候,需要再次发送一份给前端,也就是文档更新交流不及时. 接口返回结果不明确 不能直接在线测试接口,通常需要使用工具,比如postman 接口文档太多,不好管 ...
- SpringBoot 整合swagger
springBoot 整合swagger 1.pom.xml 配置 <dependency> <groupId>io.springfox</groupId> < ...
- spring-boot 集成 swagger 问题的解决
spring-boot 集成 swagger 网上有许多关于 spring boot 集成 swagger 的教程.按照教程去做,发现无法打开接口界面. 项目由 spring mvc 迁移过来,是一个 ...
- SpringBoot整合Swagger和Actuator
前言 本篇文章主要介绍的是SpringBoot整合Swagger(API文档生成框架)和SpringBoot整合Actuator(项目监控)使用教程. SpringBoot整合Swagger 说明:如 ...
- springboot之swagger快速启动
springboot之swagger快速启动 简介 介绍 可能大家都有用过swagger,可以通过ui页面显示接口信息,快速和前端进行联调. 没有接触的小伙伴可以参考官网文章进行了解下demo页面. ...
- SpringBoot整合Swagger实战
源码地址:https://github.com/laolunsi/spring-boot-examples 目前SpringBoot常被用于开发Java Web应用,特别是前后端分离项目.为方便前后端 ...
随机推荐
- 互联网那些技术 | 扒一扒互联网Markdown的那些事儿
最近感觉到 Markdown 似乎已成为各大社区的编辑器标配所支持的格式,侧面看来其设计之初的目标 " to be used as a format for writing for the ...
- 2023-11-11:用go语言,字符串哈希+二分的例题。 给定长为 n 的源串 s,以及长度为 m 的模式串 p, 要求查找源串中有多少子串与模式串匹配, s‘ 与 s 匹配,当且仅当 s‘ 与 s
2023-11-11:用go语言,字符串哈希+二分的例题. 给定长为 n 的源串 s,以及长度为 m 的模式串 p, 要求查找源串中有多少子串与模式串匹配, s' 与 s 匹配,当且仅当 s' 与 s ...
- 🔥🔥Java开发者的Python快速进修指南:面向对象基础
当我深入学习了面向对象编程之后,我首先感受到的是代码编写的自由度大幅提升.不同于Java中严格的结构和约束,Python在面向对象的实现中展现出更加灵活和自由的特性.它使用了一些独特的关键字,如sel ...
- 海量电商数据与用友YS系统数据对接案例
案例背景 客户是历史比较悠久的企业.企业内部用的系统多达十几套,专门成立信息化公司进行数字化转型,第一期需求系统旺店通的ERP以及旺店通的WMS并且启用京东的沧海外仓. 在选型ERP用友ERP和金蝶E ...
- 浅析MySQL代价模型:告别盲目使用EXPLAIN,提前预知索引优化策略
背景 在 MySQL 中,当我们为表创建了一个或多个索引后,通常需要在索引定义完成后,根据具体的数据情况执行 EXPLAIN 命令,才能观察到数据库实际使用哪个索引.是否使用索引.这使得我们在添加新索 ...
- C++ Qt开发:ToolBar与MenuBar菜单组件
Qt 是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍ToolBar ...
- AI量化策略会:可以直接上实盘的策略构建方法
一年一度的培训虽晚但到,这是BigQuant与大家走过的第五个培训年头,在过去的四年里看到很多学员的成长和蜕变,从一开始的懵懂无知,到现在对深度学习的信手拈来,BigQuant与各位学员们一样都收获颇 ...
- 为什么要实践 A+ES & CQRS ?
Wow : 基于 DDD & EventSourcing 的现代响应式 CQRS 架构微服务开发框架 中文文档 领域驱动 | 事件驱动 | 测试驱动 | 声明式设计 | 响应式编程 | 命令查 ...
- Gateway:Spring Cloud API网关组件
Gateway:Spring Cloud API网关组件 问题总结 API网关? Spring Cloud Gateway? GateWay的工作流程?(重点) Predicate断言? Filter ...
- 【OpenVINO】 使用 OpenVINO CSharp API 部署 PaddleOCR 项目介绍
前言: 在之前的项目中,我们已经使用 OpenVINOTM CSharp API 部署 PaddleOCR 全系列模型,但随着PaddleOCRv4版本发布以及OpenVINO CSharp AP ...