Java tutorial
package org.ansoya.drugs.configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.EnvironmentAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.http.ResponseEntity; import org.springframework.util.StopWatch; 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 springfox.documentation.builders.PathSelectors.regex; /** * Created by Administrator on 2016/11/6. */ @Configuration @EnableSwagger2 public class SwaggerConfiguration implements EnvironmentAware { private final Logger log = LoggerFactory.getLogger(SwaggerConfiguration.class); public static final String DEFAULT_INCLUDE_PATTERN = "/api/.*"; private RelaxedPropertyResolver propertyResolver; @Override public void setEnvironment(Environment environment) { this.propertyResolver = new RelaxedPropertyResolver(environment, "swagger."); } @Bean public Docket swaggerSpringfoxDocket() { log.debug("Starting Swagger"); StopWatch watch = new StopWatch(); watch.start(); Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()) .genericModelSubstitutes(ResponseEntity.class).select().paths(regex(DEFAULT_INCLUDE_PATTERN)) // and by paths .build(); watch.stop(); log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis()); return docket; /* ApiInfo apiInfo = new ApiInfo("sample of springboot", "sample of springboot", null, null, null, null, null); Docket docket = new Docket(DocumentationType.SWAGGER_2).select().paths(regex(DEFAULT_INCLUDE_PATTERN)).build() .apiInfo(apiInfo).useDefaultResponseMessages(false); return docket; */ } private ApiInfo apiInfo() { return new ApiInfo(propertyResolver.getProperty("title"), propertyResolver.getProperty("description"), propertyResolver.getProperty("version"), propertyResolver.getProperty("termsOfServiceUrl"), propertyResolver.getProperty("contact"), propertyResolver.getProperty("license"), propertyResolver.getProperty("licenseUrl")); } }