springboot 集成swagger2

1、pom.xml添加依赖

io.springfox

springfox-swagger2

2.9.2

io.springfox

springfox-swagger-ui

2.9.2

2、新建config包,添加Swagger配置类

importspringfox.documentation.builders.ApiInfoBuilder;

importspringfox.documentation.builders.PathSelectors;

importspringfox.documentation.builders.RequestHandlerSelectors;

importspringfox.documentation.service.ApiInfo;

importspringfox.documentation.spi.DocumentationType;

importspringfox.documentation.spring.web.plugins.Docket;

importspringfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration

@EnableSwagger2

publicclassSwaggerConfig {

@Bean

publicDocket createRestApi() {

returnnewDocket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())

.select().apis(RequestHandlerSelectors.any())

.paths(PathSelectors.any()).build();

}

privateApiInfo apiInfo() {

returnnewApiInfoBuilder().build();

}

}

3、设置程序端口,在application.properties下添加

server.port=8001

4、启动程序

你可能感兴趣的:(springboot 集成swagger2)