spring boot + swagger2 自動生成文檔
一绕沈、配置build gradle
compile('io.springfox:springfox-swagger2:2.7.0')
compile('io.springfox:springfox-swagger-ui:2.7.0')
二瞧甩、配置文件
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.xxx.xxx.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("xxx")
.description("xxx")
.termsOfServiceUrl("xxx")
.contact("ziweidajiu")
.version("1.0")
.build();
}
}
三哪怔、基本使用
@Api(value = "UserController", description = "用戶相關(guān)接口")
@ApiOperation(value="注冊用戶", notes="參數(shù)列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "tuoyouUser", value = "用戶信息", required = true ,dataType = "TuoyouUser"),
@ApiImplicitParam(paramType = "header", name = "Authorization", value = "token", dataType = "String", required = true, defaultValue = "123")
})
四、使用Security注意事項
.antMatchers("/css/**", "/js/**","/images/**", "/webjars/**", "**/favicon.ico", "/index").permitAll()
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers(
"/swagger-ui.html",
"/v2/api-docs",
"/swagger-resources",
"/swagger-resources/configuration/ui",
"/swagger-resources/configuration/security"
);
}
五该编、請求網(wǎng)址
http://localhost:8080/swagger-ui.html
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者