1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package com.yihu.figure.config;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.web.context.request.async.DeferredResult;
- import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
- import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
- import springfox.documentation.service.ApiInfo;
- import springfox.documentation.spi.DocumentationType;
- import springfox.documentation.spring.web.plugins.Docket;
- import springfox.documentation.swagger2.annotations.EnableSwagger2;
- import static com.google.common.base.Predicates.or;
- import static springfox.documentation.builders.PathSelectors.regex;
- /**
- * Created by chenweida on 2016/2/3.
- */
- @Configuration
- @EnableSwagger2
- public class SwaggerConfig extends WebMvcConfigurerAdapter {
- private static final String PUBLIC_API = "Default";
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler("swagger-ui.html")
- .addResourceLocations("classpath:/META-INF/resources/");
- registry.addResourceHandler("/webjars/**")
- .addResourceLocations("classpath:/META-INF/resources/webjars/");
- }
- @Bean
- public Docket publicAPI() {
- return new Docket(DocumentationType.SWAGGER_2)
- .groupName(PUBLIC_API)
- .genericModelSubstitutes(DeferredResult.class)
- .useDefaultResponseMessages(false)
- .forCodeGeneration(true)
- .pathMapping("/")
- .select()
- .paths(or(
- regex("/medicinal/.*"),
- regex("/diet/.*"),
- regex("/disease/.*"),
- regex("/data/.*"),
- regex("/health/.*")
- ))
- .build()
- .apiInfo(publicApiInfo());
- }
- private ApiInfo publicApiInfo() {
- ApiInfo apiInfo = new ApiInfo("居民画像API",
- "居民画像接口。",
- "1.0",
- "No terms of service",
- "admin@jkzl.com",
- "The Apache License, Version 2.0",
- "http://www.apache.org/licenses/LICENSE-2.0.html"
- );
- return apiInfo;
- }
- }
|