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. 原生js实现Base64编码解码

    注:ie10+ var str = window.btoa("liusong"); console.log(str); var s = window.atob("bGl1 ...

  2. “AS3.0高级动画编程”学习:第四章 寻路(AStar/A星/A*)算法 (下)

    在前一部分的最后,我们给出了一个寻路的示例,在大多数情况下,运行还算良好,但是有一个小问题,如下图: 很明显,障碍物已经把路堵死了,但是小球仍然穿过对角线跑了出来! 问题在哪里:我们先回顾一下ASta ...

  3. linux环境下安装oracle步骤和自启动oracle

    oracle安装步骤 一.创建用户 --注释-- /etc/passwd 用户配置文件 /etc/shadow 用户密码文件 /etc/group 组 组用户文件/etc/gshadow 组密码文件 ...

  4. List Set Map的区别

    1.读取频繁选用List 快速访问选取ArrayList,经常进行添加删除工作可以选用LinkList 2.如果你想进行有序的插入那么还是选型List,因为List是一个有序的容器 3.如果你想保证插 ...

  5. spring mvc重定向

    spring mvc重定向有三种方法. 1.return new ModelAndView("redirect:/toUrl"); 其中/toUrlt是你要重定向的url. 2.r ...

  6. 149. Max Points on a Line同一条线上的最多点数

    [抄题]: Given n points on a 2D plane, find the maximum number of points that lie on the same straight ...

  7. java 期末考试复习

      //Scanner这样写? Scanner input = new Scanner(System.in); //不断获得下一个单词 names[i] = toTitleCase(input.nex ...

  8. init.d目录下的文件定义

    init.d目录下存放的一些脚本一般是linux系统设定的一些服务的启动脚本. 系统在安装时装了好多服务,这里面就有很多对应的脚本. 执行这些脚本可以用来启动,停止,重启这些服务. 1.这些链接文件前 ...

  9. Pycharm中选择Python解释器

    新建项目后,有时候Pycharm找不到Python解释器,如果找不到的话,就会报错.报错信息: No python interpreter configured for the project 找到P ...

  10. 记一次Java Core Dump分析过程

    #背景提要 很久没有亲自动手部署代码了,命令行的亲切感越来越低.放飞了键盘,习惯了鼠标操作的windows环境.冷不丁实操部署也是不错的. 常常在部署时,运维同学对于[hs_err_pid]文件视而不 ...