1. pom

        <!-- 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>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-ui</artifactId>
<version>2.0.2</version>
</dependency>

2. 代码配置

@Configuration
@EnableSwagger2
public class SwaggerConfig { @Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(createApiInfo())
.select().apis(RequestHandlerSelectors
.basePackage("com.demo.controller")) // 对应项目的controller目录
.paths(PathSelectors.any())
.build();
} private ApiInfo createApiInfo() {
return new ApiInfoBuilder()
.title("主题")
.description("描述信息")
.termsOfServiceUrl("http://localhost")
.version("1.0.0")
.contact(new Contact("张叔叔", "http://localhost", "email@com"))
.build();
}
}

3. controller中添加 swagger注解

@Slf4j
@Api("用户控制器")
@RestController
@RequestMapping(value = "/api/v1/demo_one/user", produces = "application/json")
public class UserController implements DemoOneService { @RequestMapping(value = "/say", method = RequestMethod.GET)
public String hello(@RequestParam("name") String name) {
return "Hello " + name;
}
}

4. 登录swagger的ui界面查看在线API信息

  http://localhost:port/swagger-ui.html

  http://localhost:port/doc.html#

Spring Boot --- Swagger基本使用的更多相关文章

  1. spring boot + swagger + mysql + maven

    1.首先编写 yaml 文件,创建项目所需的接口,在swagger.io官网上生成 spring boot项目: 2.由于生成的spring boot项目是公共类的所以还需要修改成所需的项目名称,主要 ...

  2. spring boot Swagger 集成

    1. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://ww ...

  3. Spring Boot : Swagger 2

    每次修改完代码需要找原本的API时楼主的内心是痛苦的,因为一般情况下都找不到,需要重新写一份.如果使用Swagger的话,只要加几个注解就可以实时生成最新的在线API文档,而且不仅仅是文档,同时支持A ...

  4. Spring Boot + Swagger

    前言: 在互联网公司, 微服务的使用者一般分为两种, 客户端和其他后端项目(包括关联微服务),不管是那方对外提供文档 让别人理解接口 都是必不可少的.传统项目中一般使用wiki或者文档, 修改繁琐,调 ...

  5. Spring Boot 集成Swagger

    Spring Boot 集成Swagger - 小单的博客专栏 - CSDN博客https://blog.csdn.net/catoop/article/details/50668896 Spring ...

  6. Spring Boot项目简单上手+swagger配置+项目发布(可能是史上最详细的)

    Spring Boot项目简单上手+swagger配置 1.项目实践 项目结构图 项目整体分为四部分:1.source code 2.sql-mapper 3.application.properti ...

  7. HTTP RESTful服务开发 spring boot+Maven +Swagger

    这周配合第三方平台整合系统,需要提供HTTP REST服务和使用ActiveMQ推送消息,研究了下,做个笔记. 1.使用eclipse创建Spring Boot项目  创建Spring Boot项目( ...

  8. spring boot swagger-ui.html 404

    很奇怪的问题,找了好久. 因为spring boot+swagger实现起来很简单.看下面三部曲: 1.pom添加两个swagger依赖. <!-- Swagger依赖包 --> < ...

  9. Spring boot中使用springfox来生成Swagger Specification小结

    Rest接口对应Swagger Specification路径获取办法: 根据location的值获取api   json描述文件 也许有同学会问,为什么搞的这么麻烦,api json描述文件不就是h ...

随机推荐

  1. 修改tomcat的编码方式,可以解决某些get请求乱码问题

    在tomcat/conf/server.xml配置文件添加如下,修改tomcat的编码方式 <Connector URIEncoding="utf-8" connection ...

  2. 前端 跨Area后Cookie无法访问

    创建两个区域,一个是User,一个是Manage. User区域有两个页面,index1,和index2 User区域: index1:负责写入cookie index2:负责读取cookie Man ...

  3. html常用代码合集

    <!>字体效果 <h1>...</h1>标题字(最大) <h6>...</h6>标题字(最小) <b>...</b> ...

  4. C语言冷知识

    C语言属强类型语言(1)编程语言分2种:强类型语言和弱类型语言.强类型语言中所有的变量都有自己固定的类型,这个类型有固定的内存占用,有固定的解析方法:弱类型语言中没有类型的概念,所有变量全都是一个类型 ...

  5. flume知识点总结

    首先介绍一下在flume中常用的一个数据格式,以及使用该格式的优缺点:  从flume写数据到hdfs中的时候,使用二进制格式相对于使用纯文本来说是一种更好的选择,因为大多数二进制格式都有一些方法指明 ...

  6. Spring InitializingBean 接口以及Aware接口实现的原理

    关于Spring InitializingBean 接口以及Aware接口实现的其实都在 第11步中: finishBeanFactoryInitialization() 方法中完成了3部分的内容: ...

  7. centos7 微信安装

    安装过程如下: ,下载最新版本tar.gz压缩包 wget https://github.com/geeeeeeeeek/electronic-wechat/releases/download/V2. ...

  8. Gym - 100781G-Goblin Garden Guards

    题目链接:https://nanti.jisuanke.com/t/28882 解题思路:单纯的判断点是否在圆内,一一遍历圆外切正方形内的点即可,注意,该题要建个结构体数组存每个地精的位置,再bool ...

  9. wince sqlite c#

    无法找到 PInvoke DLL“SQLite.Interop.084.dll 按下面步骤操作

  10. 用windows性能监视器检测sqlserver 常见指标

    转载地址:https://www.cnblogs.com/xdong/p/4296072.html