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的更多相关文章

  1. SpringBoot配置Swagger实例(POST接收json参数)

    工程目录结构: 首先,引入jar包,只需要以下两个即可 <dependency> <groupId>io.springfox</groupId> <artif ...

  2. springboot配置swagger

    1,添加配置类 @Configuration @EnableSwagger2 @Profile({"default", "dev-online", " ...

  3. springboot 集成swagger ui

    springboot 配置swagger ui 1. 添加依赖 <!-- swagger ui --> <dependency> <groupId>io.sprin ...

  4. 整合 springboot 和 swagger出问题

    整合 springboot 和 swagger ,出现报错, org.springframework.beans.factory.UnsatisfiedDependencyException: Err ...

  5. SpringBoot集成Swagger接口管理工具

    手写Api文档的几个痛点: 文档需要更新的时候,需要再次发送一份给前端,也就是文档更新交流不及时. 接口返回结果不明确 不能直接在线测试接口,通常需要使用工具,比如postman 接口文档太多,不好管 ...

  6. SpringBoot 整合swagger

    springBoot 整合swagger 1.pom.xml 配置 <dependency> <groupId>io.springfox</groupId> < ...

  7. spring-boot 集成 swagger 问题的解决

    spring-boot 集成 swagger 网上有许多关于 spring boot 集成 swagger 的教程.按照教程去做,发现无法打开接口界面. 项目由 spring mvc 迁移过来,是一个 ...

  8. SpringBoot整合Swagger和Actuator

    前言 本篇文章主要介绍的是SpringBoot整合Swagger(API文档生成框架)和SpringBoot整合Actuator(项目监控)使用教程. SpringBoot整合Swagger 说明:如 ...

  9. springboot之swagger快速启动

    springboot之swagger快速启动 简介 介绍 可能大家都有用过swagger,可以通过ui页面显示接口信息,快速和前端进行联调. 没有接触的小伙伴可以参考官网文章进行了解下demo页面. ...

  10. SpringBoot整合Swagger实战

    源码地址:https://github.com/laolunsi/spring-boot-examples 目前SpringBoot常被用于开发Java Web应用,特别是前后端分离项目.为方便前后端 ...

随机推荐

  1. 文件 inode 与 no space left on device 异常

    转载请注明出处: 文件inode 在 Linux 文件系统中,每一个文件或目录都会有一个 inode,它是一个数据结构,用于存储文件的元数据,比如文件的权限.所有者.大小.创建和修改的时间等.inod ...

  2. 动态规划——提高Ⅴ(DP优化)

    单调队列优化DP 其实单调队列就是一种队列内的元素有单调性(单调递增或者单调递减)的队列,答案(也就是最优解)就存在队首,而队尾则是最后进队的元素.因为其单调性所以经常会被用来维护区间最值或者降低DP ...

  3. L2-034 口罩发放

    重点在阅读理解能力 身份证号必须是18位数字,话说平时咱们身份证也可以带个X啥的啊. 合法状态就是只要身份证合格就行,一开始我还想是它犯病,然后申请了口罩才算一个合法记录. 后边输出状态为1的人,一定 ...

  4. Python 潮流周刊#27:应该如何处理程序的错误?

    你好,我是猫哥.这里每周分享优质的 Python.AI 及通用技术内容,大部分为英文.本周刊开源,欢迎投稿.另有电报频道作为副刊,补充发布更加丰富的资讯. 产品推荐 Walles.AI 是一款适用于所 ...

  5. 【公告】luogu blog (daiyulong20120222) 即将迁移!

    \[\huge\text{luogu blog (daiyulong20120222) 即将迁移到 cnblogs!}\\ \] \[\huge\color{blue}\text{https://ww ...

  6. vue禁止浏览器F5进行刷新和监听浏览器刷新事件

    项目中有个这样的需求: 进入视频播放页后,添加一个标识,为了防止用户一次播放多个视频,当离开该页面后,如果是从当前正在播放的视频页面离开的,则离开播放页时清除标识,如果是不是则不清除,并且禁止用户按F ...

  7. 【uniapp】学习笔记day02 | uniapp搭建

    起因:需要做一个小程序,家人们谁懂啊,老师我真的不会做,由于懒得看视频学习,于是只能看博客学习了. uniapp 好处: 1.不用关心适配问题 2.可以发布到各大平台的小程序 3.上手容易,使用vue ...

  8. MySQL大表设计怎么做?

    MySQL是一种常用的关系型数据库管理系统,它在处理大表时需要特别注意设计和优化.下面将详细介绍MySQL大表的设计原则和优化策略. 1. 数据库设计 数据库范式化:将数据按照规范的关系模型进行拆分和 ...

  9. 35个超实用excel快捷键

    以下是一些常用的Excel快捷键,希望对你有所帮助.如果你想要了解更多快捷键,可以参考Excel的官方文档或者在网上搜索相关信息. Ctrl + C:复制选定的单元格或单元格范围. Ctrl + X: ...

  10. 可视化学习:WebGL的基础使用

    引言 继续复习可视化的学习.WebGL和其他Web端的图形系统存在很大的不同,是OpenGL ES规范在浏览器的实现,它最大的不同就在于它更接近底层,可以由开发者直接操作GPU来实现绘图,性能很好,可 ...