Spring Boot --- Swagger基本使用
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基本使用的更多相关文章
- spring boot + swagger + mysql + maven
1.首先编写 yaml 文件,创建项目所需的接口,在swagger.io官网上生成 spring boot项目: 2.由于生成的spring boot项目是公共类的所以还需要修改成所需的项目名称,主要 ...
- spring boot Swagger 集成
1. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://ww ...
- Spring Boot : Swagger 2
每次修改完代码需要找原本的API时楼主的内心是痛苦的,因为一般情况下都找不到,需要重新写一份.如果使用Swagger的话,只要加几个注解就可以实时生成最新的在线API文档,而且不仅仅是文档,同时支持A ...
- Spring Boot + Swagger
前言: 在互联网公司, 微服务的使用者一般分为两种, 客户端和其他后端项目(包括关联微服务),不管是那方对外提供文档 让别人理解接口 都是必不可少的.传统项目中一般使用wiki或者文档, 修改繁琐,调 ...
- Spring Boot 集成Swagger
Spring Boot 集成Swagger - 小单的博客专栏 - CSDN博客https://blog.csdn.net/catoop/article/details/50668896 Spring ...
- Spring Boot项目简单上手+swagger配置+项目发布(可能是史上最详细的)
Spring Boot项目简单上手+swagger配置 1.项目实践 项目结构图 项目整体分为四部分:1.source code 2.sql-mapper 3.application.properti ...
- HTTP RESTful服务开发 spring boot+Maven +Swagger
这周配合第三方平台整合系统,需要提供HTTP REST服务和使用ActiveMQ推送消息,研究了下,做个笔记. 1.使用eclipse创建Spring Boot项目 创建Spring Boot项目( ...
- spring boot swagger-ui.html 404
很奇怪的问题,找了好久. 因为spring boot+swagger实现起来很简单.看下面三部曲: 1.pom添加两个swagger依赖. <!-- Swagger依赖包 --> < ...
- Spring boot中使用springfox来生成Swagger Specification小结
Rest接口对应Swagger Specification路径获取办法: 根据location的值获取api json描述文件 也许有同学会问,为什么搞的这么麻烦,api json描述文件不就是h ...
随机推荐
- 关于Encode in UTF-8 without BOM
定义BOM(Byte Order Mark),字节顺序标记,出现在文本文件头部,Unicode编码标准中用于标识文件是采用哪种格式的编码.它的编码是FEFF. 说明 在 UTF-8 文件中放置 BOM ...
- js实现图片上传预览功能,使用base64编码来实现
实现图片上传的方法有很多,这里我们介绍比较简单的一种,使用base64对图片信息进行编码,然后直接将图片的base64信息存到数据库. 但是对于系统中需要上传的图片较多时并不建议采用这种方式,我们一般 ...
- Python:Fintech产品的第一语言
来源商业新知,原标题:为什么说Python是Fintech与金融变革的秘密武器 人生苦短,不止程序员,Python正在吸引来自金融领域大佬们的青睐目光. 金融科技的风口下,无数传统金融人都想从中掘一桶 ...
- service mysqld start,Failed to start mysqld.service: Access denied
service mysqld start 然后报: ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===Authentic ...
- actuator/hystrix.stream 没有反应的方法
http://localhost:8086/actuator/hystrix.stream 在启动类加上,就ok了 @Bean public ServletRegistrationBean hystr ...
- 云笔记项目-Spring事务学习_测试准备
在做云笔记项目的过程中,顺便简单的学习了Spring的事务概念,业务以如果添加笔记,则增加用户星星数目作为例子,引入了事务的概念.类似注册送积分之类的,云笔记项目以增加笔记就送星星来说明事务.具体在添 ...
- 安装64位office时,弹出提示,要求卸载32位office
运行 regedit,进入到HKEY_CLASSES_ROOT\Installer\Products下,删除0000510开头的项或00002开头项.然后重启计算机. 参考: https://blo ...
- mysql面试题集
Mysql 的存储引擎,myisam和innodb的区别. 答: 1.MyISAM 是非事务的存储引擎,适合用于频繁查询的应用.表锁,不会出现死锁,适合小数据,小并发.5.6之前默认myisam 2. ...
- swift 分组tableview 设置分区投或者尾部,隐藏默认间隔高度
1.隐藏尾部或者头部,配套使用 //注册头部id tv.register(JYWithdrawalRecordSectionView.self, forHeaderFooterViewReuseIde ...
- 【Spring】浅谈spring为什么推荐使用构造器注入
一.前言 Spring框架对Java开发的重要性不言而喻,其核心特性就是IOC(Inversion of Control, 控制反转)和AOP,平时使用最多的就是其中的IOC,我们通过将组件交由S ...