引入的swagger版本:
<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>
引入的springboot版本:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
引入的springframework版本:
5.0.1.RELEASE
swagger配置:
@Configuration
// @EnableWebMvc //NOTE: Only needed in a non-springboot application
@EnableSwagger2
@ComponentScan("com.solin.template.web")
public class SwaggerAPIPluginConfig {
@Bean //Don't forget the @bean annotation
public Docket customImplementation() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("springboot-template").forCodeGeneration(true).pathMapping("/")
.select().paths(paths()).build()
.apiInfo(apiInfo()).useDefaultResponseMessages(false);
}
private Predicate<String> paths(){
return Predicates.and(PathSelectors.regex("/app/.*"), Predicates.not(PathSelectors.regex("/error")));
}
private ApiInfo apiInfo() {
Contact contact = new Contact("admin", "", "");
ApiInfo apiInfo = new ApiInfoBuilder()
.title("springboot template API接口")//大标题
.description("REST风格API")//小标题
.contact(contact)//作者
.termsOfServiceUrl("")
.version("0.1")//版本
.license("主页")//链接显示文字
.licenseUrl("")//网站链接
.build();
return apiInfo;
}
}
运行后,一直提示:fetching resource list: http://localhost:8080/template/v2/api-docs?group=springboot-templat
确认配置无误,最后检查是springframework版本问题,改成 5.0.8.RELEASE 后正常显示
所以出现类似问题,检查下spring的版本,因为swagger框架代码中会使用spring,可能版本问题会导致出现问题。