|
@@ -0,0 +1,76 @@
|
|
|
+package com.gyee.runeconomy.config;
|
|
|
+
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
+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;
|
|
|
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Swagger 配置文件
|
|
|
+ * @ClassName: Swagger
|
|
|
+ * @Description: 配置文件
|
|
|
+ * @author gyee
|
|
|
+ * @date 2022年11月10日
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Configuration(value="true")
|
|
|
+@EnableSwagger2 //启动swagger注解 启动服务,浏览器输入"http://localhost:8080/swagger-ui.html"
|
|
|
+public class SwagerrConfiguration implements WebMvcConfigurer {
|
|
|
+
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public Docket createRestApi() {
|
|
|
+ return new Docket(DocumentationType.SWAGGER_2)
|
|
|
+ //.host("")
|
|
|
+ // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
|
|
|
+ .apiInfo(apiInfo())
|
|
|
+ // 设置哪些接口暴露给Swagger展示
|
|
|
+ .select()
|
|
|
+ // 扫描所有有注解的api,用这种方式更灵活
|
|
|
+ .apis(RequestHandlerSelectors.basePackage("com.gyee.runeconomy"))
|
|
|
+ // 扫描指定包中的swagger注解
|
|
|
+ //.apis(RequestHandlerSelectors.basePackage("com.gyee.frame.controller"))
|
|
|
+ // 扫描所有 .apis(RequestHandlerSelectors.any())
|
|
|
+ .paths(PathSelectors.any())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ private ApiInfo apiInfo() {
|
|
|
+ return new ApiInfoBuilder()
|
|
|
+ //设置标题
|
|
|
+ .title("后台管理API文档")
|
|
|
+ //描述
|
|
|
+ .description("后台管理项目")
|
|
|
+ //作者信息
|
|
|
+ //.contact(new Contact(v2Config.getName(), null, V2Config.getEmail_account()))
|
|
|
+ //服务条款URL
|
|
|
+ .termsOfServiceUrl("")
|
|
|
+ //版本
|
|
|
+ .version("版本号:1.0")
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
+
|
|
|
+ // 解决静态资源无法访问
|
|
|
+
|
|
|
+ registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
|
|
|
+
|
|
|
+ // 解决swagger无法访问
|
|
|
+
|
|
|
+ registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
|
|
|
+
|
|
|
+ // 解决swagger的js文件无法访问
|
|
|
+
|
|
|
+ registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
+
|
|
|
+ }
|
|
|
+}
|