spring-boot - 在 swagger ui 上找不到授权按钮
问题描述
我正在做一个春季启动项目。当我访问 swagger ui() 时,没有授权按钮。这是我的配置类
public class Configuration {
private ApiKey apiKey() {
return new ApiKey("JWT", "Authorization", "header");
}
private SecurityContext securityContext() {
return SecurityContext.builder().securityReferences(defaultAuth()).build();
}
private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Arrays.asList(new SecurityReference("JWT", authorizationScopes));
}
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
.securityContexts(Arrays.asList(securityContext())).securitySchemes(Arrays.asList(apiKey())).select()
.apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
}
private ApiInfo apiInfo() {
return new ApiInfo("My REST API", "Some custom description of API.", "1.0", "Terms of service",
new Contact("some company", "www.someplace.net", "someone@gmail.com"), "License of API",
"API license URL", Collections.emptyList());
}}
我正在使用 springfox 版本 3
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
我确实看到了我的 API,但我没有看到授权按钮或我的应用信息。我可能错过了什么?
解决方案
推荐阅读
- html - 使用 CSS 的计划图标
- javascript - 如何在运行函数之前等待变量初始化?(反应)
- angular - 循环依赖 Angular(只是文件名)
- python - pandas DataFrame:删除某些值时如何避免'ValueError:little-endian编译器不支持Big-endian缓冲区'
- javascript - 为什么 Kyle Simpson 的 OLOO 方法感觉像是与 Typescript 潮流背道而驰?
- google-cloud-platform - 如何使用 DLP api 从存储桶 (GCS) 读取镶木地板文件并取消识别到特定列?
- android - 如何使用 Retrofit 从 Json 数组列表中检索 MpAndroid 图表内的数据?
- java - 如何随机排列一个数组,以便一次打印 x% 的值?
- python - 如何打印列表的所有元素,而不仅仅是最后一个?
- python - 如何强制 matplotlib 在 Y 轴上使用指数符号?