我尝试将config swagger用于我的Spring引导应用程序。我将此链接用于配置https://www.baeldung.com/spring-boot-swagger-jwt。我改变了一些部分
@Bean
public Docket swaggerCustomConfiguration() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiDetails())
.securityContexts(Collections.singletonList(securityContext()))
.securitySchemes(Collections.singletonList(apiKey()))
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build()
.protocols(swaggerProtocols)
.host(swaggerHostUrl);
}
private ApiInfo apiDetails() {
return new ApiInfoBuilder()
.title(swaggerTitle)
.description(swaggerDescription)
.termsOfServiceUrl(termsOfServiceUrl)
.version("v" + serverVersionCode + "-" + serverVersionName)
.build();
}
private ApiKey apiKey() {
return new ApiKey("Bearer", "Authorization", "header");
}
private SecurityContext securityContext() {
return SecurityContext.builder().securityReferences(defaultAuth()).build();
}
private List<SecurityReference> defaultAuth() {
final AuthorizationScope readScope = new AuthorizationScope("read", "read scope");
final AuthorizationScope writeScope = new AuthorizationScope("write", "write scope");
return Collections.singletonList(new SecurityReference("Bearer",
new AuthorizationScope[]{readScope, writeScope}));
}但我不知道的是AuthorizationScope。我不知道AuthorizationScope到底是怎么回事。可以介绍任何链接来帮助我。
发布于 2021-09-20 19:31:18
我知道这不是你问题的确切答案,但你可以考虑搬到springdoc。它是一个较新的库,在我看来,它是一个更好更容易使用的库。看一看:
Springfox已经成为一个痛苦的使用,有如此多的bug和难以配置的功能。
https://stackoverflow.com/questions/69251722
复制相似问题