我有一个Spring Boot应用程序,它使用swagger-ui公开它的api。现在,直到我使用springfox-swagger-ui 2.6.1版,我的代码才能正常工作。但是,当我将版本更新为2.7.0时,会引发一个错误,表明ApiInfo方法已被弃用。谁能告诉我一种替代方案,该方案将尽可能少地修改现有代码,并成功地在Swagger UI中将信息作为描述运行在应用程序中。我在这里给出了swagger config的现有代码...
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.select()
.apis(RequestHandlerSelectors.basePackage("com.xyz.abc"))
.paths(regex("/api.*"))
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfo(
"My-Project Api",
"Api for My Project",
"V1",
"NA terms of service url",
new Contact("Team Name", "www.somexyzteamcontact.com, "NA"),
"A license given",
"NA");
}
}
以及我在我的项目中使用的摇摇欲坠的依赖关系:
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.7.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.7.0'
[尝试以下操作,使用ApiInfoBuilder构建API
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("API Reference").version("1.0.0")
.description("something")
.build();
}