(2)、配置swagger->configio.springfox springfox-swagger2 3.0.0 io.springfox springfox-swagger-ui 2.9.2
package com.example.swagger.config;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2 //开启swagger
public class SwaggerConfig {
}
(3)、写@Contrller进行测试
package com.example.swagger.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ApiController {
@GetMapping("/testApi")
public String test(){
return "测试swagger";
}
}
(4)、启动项目发现失败
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
在application.yml中或者application.properties中加入配置修改升级之后的版本与springboot不兼容的问题
spring.mvc.pathmatch.matching-strategy=ant_path_matcher(5)、重新启动项目测试
访问ip http://localhost:8001/swagger-ui.html,失败
更换版本,解决问题(但是在application.yml中或者application.properties中加入有关swagger的配置不能删除,否则即使降低版本也会依然报错)
io.springfox springfox-swagger2 2.9.2 io.springfox springfox-swagger-ui 2.9.2
所以归根结底是版本的问题才导致出现一系列的问题!但是要注意即使更换版本,在application.yml中或者application.properties中加入有关swagger的配置spring.mvc.pathmatch.matching-strategy=ant_path_matcher依然不能删除
可以看到通过访问ip http://localhost:8001/swagger-ui.html看到我们自己写的@Controller中有多少个api接口,更方便团队合作开发!



