New file:
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;/** * api doc -- springfox swagger configuration */@Configuration @enableswagger2public class swaggerconfiguration implements environmentaware { &nbsP; 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 (); &nbSp; docket swaggerspringmvcplugin = 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 swaggerspringmvcplugin; } 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") ); }}
The default_include_pattern should fit into your own interface format.
Maven Dependencies to use:
<springfox.version>2.2.2</springfox.version><dependency> <groupid>io.springfox</ Groupid> <artifactId>springfox-swagger-ui</artifactId> <version>${springfox.version}</ Version></dependency><dependency> <groupId>io.springfox</groupId> <artifactId> Springfox-swagger2</artifactid> <version>${springfox.version}</version></dependency>
Visit the following URL to see the effect:
Http://localhost:8080/swagger-ui.html
In addition, you can insert it into your own web page via an iframe:
<iframe src= "swagger-ui.html" frameborder= "0" marginheight= "0" marginwidth= "0" width= "100%" height= "" "Scrolli ng= "Auto" target= ' _top ' ></iframe>
Spring boot uses springfox swagger to showcase RESTful API doc