【发布时间】:2019-11-12 02:41:43
【问题描述】:
我有一个 Spring Boot 项目,其中 springfox-swagger-2 作为依赖项。
使用的版本:
- Spring Boot:1.5.9.RELEASE
- springfox-swagger-2:2.7.0
这是配置:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
Docket api = new Docket(DocumentationType.SWAGGER_2);
api
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
api.apiInfo(apiInfo())
.globalOperationParameters(Lists.newArrayList(new ParameterBuilder()
.name("Example api info")
.description("description")
.modelRef(new ModelRef("string"))
.parameterType("parameter type example").build()))
;
return api;
}
@SuppressWarnings("rawtypes")
private ApiInfo apiInfo() {
Contact contact = new Contact("name", "url", "email");
Collection<VendorExtension> vendorExtensions = new ArrayList<>();
return new ApiInfo("title", "description", "version", "termsOfServiceUrl", contact, "license", "licenseUrl", vendorExtensions);
}
}
应用程序正确启动,但 url /v2/api-docs 得到 HTTP 404 Not Found
即使 /swagger-ui.html 也不可用,添加 springfox-swagger-ui 的依赖项
引导日志没有报告任何错误。
我已经尝试找到其他类似问题的答案,但其中任何一个都有效!
任何帮助将不胜感激。
【问题讨论】:
-
springfox-swagger-ui 依赖添加了吗?
-
当然版本和springfox-swagger-2一样
-
你好 @AlessandroC 你使用的是 Spring Security,如果是,你可能需要为其添加配置
-
@Patel Romil 嗨,是的,我有 Spring Security,而且我已经有了它的配置!
-
你好@AlessandroC 请看一个适合我的答案
标签: spring spring-boot swagger swagger-2.0 springfox