1.导入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
2.配置类
@Configuration//配置类
@EnableSwagger2 //swagger注解
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("webApi")
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.enjoyu.yulong.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Springboot-api APIs")
.description("Springboot-api APIs")
.termsOfServiceUrl("NO terms of service")
.version("1.0")
.build();
}
}
3.访问
启动项目,访问 http://localhost:端口号/项目名/swagger-ui.html
出现如图页面
成功。
4.一些注解