From eb28b5d534967524ea5bcc9cc1411f4723591c9e Mon Sep 17 00:00:00 2001 From: yangzhengze <1403014932@qq.com> Date: Tue, 29 May 2018 22:53:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0swagger=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 15 +++++++ .../framework/config/ResourcesConfig.java | 4 ++ .../ruoyi/framework/config/SwaggerConfig.java | 41 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/main/java/com/ruoyi/framework/config/SwaggerConfig.java diff --git a/pom.xml b/pom.xml index d741fd75e..183a2bb30 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,7 @@ 1.7 2.3.0 2.3.2 + 2.7.0 @@ -215,6 +216,20 @@ + + + + io.springfox + springfox-swagger2 + ${swagger.version} + + + + + io.springfox + springfox-swagger-ui + ${swagger.version} + diff --git a/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java b/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java index 4e205513a..bdc284f46 100644 --- a/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java +++ b/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java @@ -37,5 +37,9 @@ public class ResourcesConfig extends WebMvcConfigurerAdapter public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/profile/**").addResourceLocations("file:" + RuoYiConfig.getProfile()); + + /**swagger配置*/ + registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); + registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); } } \ No newline at end of file diff --git a/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java b/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java new file mode 100644 index 000000000..be860614e --- /dev/null +++ b/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java @@ -0,0 +1,41 @@ +package com.ruoyi.framework.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.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +/** + * Swagger2的接口配置 + */ +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + //.apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.*.*.controller")) + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build(); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("系统接口列表") + .description("API接口测试平台\",\n" + + " \"提供后台所有Restful接口\",") + .termsOfServiceUrl("http://localhost/swagger-ui.html") + .contact(new Contact("RuoYi", "https://gitee.com/y_project/RuoYi", "1403014932@qq.com")) + .version("1.1.0") + .build(); + } +}