spring|spring boot + swagger2 自动生成文档
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 = "https://www.it610.com/article/UserController", description = "用户相关接口")
- 方法上方添加
@ApiOperation(value="https://www.it610.com/article/注册用户", notes="参数列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "tuoyouUser", value = "https://www.it610.com/article/用户信息", required = true ,dataType = "TuoyouUser"),
@ApiImplicitParam(paramType = "header", name = "Authorization", value = "https://www.it610.com/article/token", dataType = "String", required = true, defaultValue = "https://www.it610.com/article/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"
);
}
五、请求网址
http://localhost:8080/swagger-ui.html
推荐阅读
- Activiti(一)SpringBoot2集成Activiti6
- SpringBoot调用公共模块的自定义注解失效的解决
- 解决SpringBoot引用别的模块无法注入的问题
- 2018-07-09|2018-07-09 Spring 的DBCP,c3p0
- spring|spring boot项目启动websocket
- Spring|Spring Boot 整合 Activiti6.0.0
- Spring集成|Spring集成 Mina
- springboot使用redis缓存
- Spring|Spring 框架之 AOP 原理剖析已经出炉!!!预定的童鞋可以识别下发二维码去看了
- Spring|Spring Boot之ImportSelector