Swagger2配置

Swagger2 Api接口管理

pom依赖


	io.springfox
	springfox-swagger-ui
	2.6.1


	io.springfox
	springfox-swagger2
	2.6.1

开启Swagger2配置

@configuration
@EnableSwagger2
@ConditionalOnProperty(name = "swagger.enale", havingValue = "true")
public class ApiSwagger2Config {
	
	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
						.apiInfo(apiInfo())
						.select()
						.apis(RequestHandlerSelectors.basePackage("com.yck.controller")).paths(PathSelectors.any())
						.build();
	}

	// 构建api文档详细信息
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
					.title("API")
					.termsOfServiceUrl("http://localhost:8081/")
					.version("1.0.0")
					.description("API DESC")
					.build();
	}
	
}

swagger.enale = true / false 可在配置文件中设置,生产环境建议关闭

@ConditionalOnProperty(name = "swagger.enale", havingValue = "true")

系统自带的一些path拦截,需要放行swagger自带的资源

/swagger.*
/webjars/.*
/v2/api.*

controller类上增加@Api注解

@Api(value = "xxxx描述")

接口上增加注解

@ApiOperation(value = "查询xxxx")

访问地址:
自己系统访问 + swagger

http://localhost:8080/swagger-ui.html

你可能感兴趣的:(java,springboot,restful,java,intellij-idea,spring,boot)