java springboot 初体验 (八)对接swagger2
- 上一篇
- java springboot 初体验 (七)对接链路追踪
- https://www.cnblogs.com/zwjvzwj/p/16613085.html
- pom文件添加依赖包
-
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <!-- 接口文档——Swagger2的使用 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${spring-swagger2.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <!-- 接口文档——Swagger2的使用 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${spring-swagger-ui.version}</version> </dependency>
-
- 注册配置
-
package com.zwj.zwjproject.configuration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; /** * @ClassName: swagger2Configuration * @Author zhangwujie * @Date 2022/8/22 7:03 下午 * @Description: */ @Configuration //声明该类为配置类 public class Swagger2Configuration { @Bean public Docket customDocket() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.zwj.zwjproject.controller"))//扫描的包路径 .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("zwj-project 项目接口文档名称")//文档说明 .version("1.0.0")//文档版本说明 .build(); } }
-
-
添加配置
- 在配置文件application.yml中或者apollo中国呢配置
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
- 在配置文件application.yml中或者apollo中国呢配置
- 启动服务
- 查看对外文档
- http://localhost:8101/swagger-ui.html
- 域名和端口按你的项目进行修改
- 下一篇
- java springboot 初体验 (九)对接http请求
- https://www.cnblogs.com/zwjvzwj/p/16614205.html
本文来自博客园,作者:zwjvzwj,转载请注明原文链接:https://www.cnblogs.com/zwjvzwj/p/16614128.html