springboot整合swagger2,并使用bootstrap-ui

依賴:

<dependency>

? ? <groupId>io.springfox</groupId>

? ? <artifactId>springfox-swagger2</artifactId>

? ? <version>2.9.2</version>

</dependency>

<dependency>

? ? <groupId>com.github.xiaoymin</groupId>

? ? <artifactId>swagger-bootstrap-ui</artifactId>

? ? <version>1.9.6</version>

</dependency>


配置文件:

@Configuration

@EnableSwagger2

@EnableSwaggerBootstrapUI

public class SwaggerConfigimplements WebMvcConfigurer{

? ? @Override

? ? public void addResourceHandlers(ResourceHandlerRegistry registry) {

? ? ? ? registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");

? ? ? ? registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");

? ? }

? ? @Bean

? ? public DocketcreateRestApi() {

? ? ? ? return new Docket(DocumentationType.SWAGGER_2)

? ? ? ? ? ? ? ? .apiInfo(apiInfo())

? ? ? ? ? ? ? ? .select()

? ? ? ? ? ? ? ? //此包路徑下的類,才生成接口文檔

? ? ? ? ? ? ? ? .apis(RequestHandlerSelectors.basePackage("com.example"))

? ? ? ? ? ? ? ? //加了ApiOperation注解的類,才生成接口文檔

? ? ? ? ? ? ? ? .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))

? ? ? ? ? ? ? ? .paths(PathSelectors.any())

? ? ? ? ? ? ? ? .build();

? ? ? ? //.globalOperationParameters(setHeaderToken());

? ? }

? ? private ApiInfoapiInfo() {

? ? ? ? return new ApiInfoBuilder()

? ? ? ? ? ? ? ? .title("SpringBoot利用Swagger構(gòu)建API文檔")

? ? ? ? ? ? ? ? .description("使用RestFul風(fēng)格, 創(chuàng)建人:longma4")

? ? ? ? ? ? ? ? .termsOfServiceUrl("https://github.com/cicadasmile")

? ? ? ? ? ? ? ? .version("version 1.0")

? ? ? ? ? ? ? ? .build();

? ? }

}


啟動類注解:

@SpringBootApplication

@MapperScan("com.example.dao")

@EnableSwagger2

public class SampleWebJspApplicationextends SpringBootServletInitializer{

? *********

}


注意:這里我的swagger配置文件和啟動類在同一個目錄才可以。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容