1.添加依赖
<!--添加swagger2相关概念-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!--添加swagger-ui相关功能-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
2.配置文件:SwggerConfig
@Configuration//告诉Spring容器,这个类是一个配置类
@EnableSwagger2//启用Swagger2功能
public class SwaggerConfig {
@Bean
public Docket createResApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com"))//com包下的所有API都交给Swagger2管理
.paths(PathSelectors.any()).build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("演示项目API")//标签
.description("演示项目")//描述
.version("1.0")//版本
.build();
}
}
3.访问地址
http://localhost:8080/swagger-ui.html
4.问题
Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
#配置Swagger-ui
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
Swagger常用注解