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 {@Beanpublic 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常用注解
?