标签:color ORC type 扫码 pre cto bsp contex 就是
<!-- swagger2 rest api start--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency> <!-- swagger2 rest api end-->
import org.springframework.boot.context.properties.ConfigurationProperties; 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.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * @author TangZedong * @apiNote swagger2配置文件 * @since 2018/9/4 10:46 */ @Configuration @EnableSwagger2 @ConfigurationProperties public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .forCodeGeneration(true)
.groupName("指定group的名称,groupName不能重复") .select() .apis(RequestHandlerSelectors.basePackage("这里是你需要扫描的包路径")) //过滤生成链接 .paths(PathSelectors.any()) .build() .apiInfo(apiInfo()); } /** * the api info * * @return api info */ private ApiInfo apiInfo() { return new ApiInfoBuilder() .license("Apache License Version 2.0") .title("blogspot") .description("api docs") .contact(new Contact("tangzedong", "https://www.cnblogs.com/HackerBlog/", "tangzedong.programmer@gmail.com")) .version("1.0") .build(); } }
然后启动spring boot服务器,在网页上输入网址:http://localhost:8080/swagger-ui.html 你就可以看见swagger的页面了
spring boot项目添加swagger 2.7.0(只需两步操作)
标签:color ORC type 扫码 pre cto bsp contex 就是
原文地址:https://www.cnblogs.com/HackerBlog/p/9584513.html