parent
2c15d4f95b
commit
a3e85432cc
@ -0,0 +1,27 @@
|
|||||||
|
package com.example.demo.config;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
|
import io.swagger.v3.oas.models.info.License;
|
||||||
|
import org.springdoc.core.GroupedOpenApi;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpringDoc API文档相关配置
|
||||||
|
* Created by macro on 2022/3/4.
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class SpringDocConfig {
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi publicApi() {
|
||||||
|
return GroupedOpenApi.builder()
|
||||||
|
.group("")
|
||||||
|
.pathsToMatch("")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,51 +0,0 @@
|
|||||||
package com.example.demo.config;
|
|
||||||
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Profile;
|
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author lyr
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Profile({"prd","test","dev"})
|
|
||||||
@Configuration
|
|
||||||
@EnableSwagger2
|
|
||||||
@EnableSwaggerBootstrapUI
|
|
||||||
public class SwaggerConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket api() {
|
|
||||||
// List<RequestParameter> globalRequestParameters = new ArrayList<>();
|
|
||||||
// RequestParameter build = new RequestParameterBuilder().name("abc").description("添加swagger公共请求参数abc").required(true).build();
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
.select()
|
|
||||||
.apis(RequestHandlerSelectors.basePackage("com.qkc.stat.controller"))
|
|
||||||
.paths(PathSelectors.any())
|
|
||||||
.build()
|
|
||||||
// .globalRequestParameters(globalRequestParameters)
|
|
||||||
// .securitySchemes(securitySchemes()) //添加token
|
|
||||||
// .securityContexts(securityContexts()) //swagger配置页面访问是否需要传token
|
|
||||||
.apiInfo(apiInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
private ApiInfo apiInfo() {
|
|
||||||
return new ApiInfoBuilder()
|
|
||||||
.title("统计信息服务")
|
|
||||||
.description("统计服务相关接口")
|
|
||||||
.termsOfServiceUrl("127.0.0.1")
|
|
||||||
.version("1.0.0")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package com.example.demo.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: lyr
|
|
||||||
* @Date: 2021-04-21 10:13
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class WebMvnConfig extends WebMvcConfigurationSupport {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addCorsMappings(CorsRegistry registry) {
|
|
||||||
|
|
||||||
registry.addMapping("/**")
|
|
||||||
.allowedOrigins("*")
|
|
||||||
.allowedMethods("PUT", "DELETE", "GET", "POST", "OPTIONS")
|
|
||||||
.allowCredentials(true).maxAge(3600);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
||||||
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
|
||||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue