失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > [Swagger2]SpringBoot集成Swagger

[Swagger2]SpringBoot集成Swagger

时间:2022-05-17 03:01:34

相关推荐

[Swagger2]SpringBoot集成Swagger

SpringBoot集成Swagger

引入依赖

<!-- /artifact/io.springfox/springfox-swagger2 --><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version></dependency><!-- /artifact/io.springfox/springfox-swagger-ui --><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version></dependency>

编写HelloController,测试确保运行成功!

package com.xxxx.swagger2.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HelloController {@RequestMapping(value = "/hello")public String hello(){return "hello";}}

要使用Swagger,我们需要编写一个配置类-SwaggerConfig来配置 Swagger

@Configuration //配置类@EnableSwagger2// 开启Swagger2的自动配置public class SwaggerConfig {}

访问测试 :http://localhost:8080/swagger-ui.html ,可以看到swagger的界面;

如果觉得《[Swagger2]SpringBoot集成Swagger》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。