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(); + } +}