spring boot整合引入swagger2
2018-07-11 14:16
351 查看
版权声明:转载请注明出处 https://blog.csdn.net/qq_40738872/article/details/80999543
1、首先打开项目的pom.xml文件添加相关依赖
<!--引入swagger2--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.8.0</version> </dependency> <!--引入swagger-ui--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.8.0</version> </dependency>2、新建一个包放置Swagger2配置类(例如:com.we.weshop.config.Swagger2Configuration.java)
package com.we.weshop.config; 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; /** * Swagger2 配置类 * @author E * @date 2018/6/4 11:01 */ @Configuration public class Swagger2Configuration { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.we.weshop")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("WESHOP API文档") .description("power by E,1565181015@qq.com") .termsOfServiceUrl("https://blog.csdn.net/qq_40738872") .version("1.0") .build(); } }3、Reimport 一下pom.xml 文件下载相关jar包
4、在启动类上添加@EnableSwagger2 注解
5、controller在方法上添加相关注解(例如如下)
@GetMapping("/index") @ApiOperation(value = "返回后台管理主页",notes = "返回后台管理页面") public String index(){ return "index"; }6、运行项目,访问http://localhost:8090/swagger-ui.html(注:端口号因人而异)
相关文章推荐
- Spring Boot整合Swagger2的完整步骤详解
- Springboot整合swagger2项目的部署问题
- Spring Boot整合Swagger2
- Swagger(一) SpringBoot整合Swagger2简单的例子
- spring boot整合Swagger2的示例代码
- springboot整合swagger2企业项目搭建
- spring boot 整合swagger2 实现动态生成接口文档
- SpringBoot(七):SpringBoot整合Swagger2
- Spring Boot 整合mybatis 与 swagger2
- springboot整合Swagger2
- SpringBoot和Swagger2整合的小demo
- Spring boot 整合 swagger2
- 个人推荐:SpringBoot整合Swagger2
- SpringBoot实战之12 整合restful工具swagger2
- spring boot 整合Swagger2
- SpringBoot整合Swagger2
- SpringBoot之整合Swagger2
- 二、SpringBoot 整合 swagger2 (swagger2 版本 2.8.0)
- SpringBoot整合Swagger2
- Spring Boot 整合Spring Security 和Swagger2 遇到的问题小结