我使用Bearer token 访问我的api。所以我像这样配置我的招摇:@Configuration@EnableSwagger2public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("br.com.lumera.intimacaoapi.controller")) .paths(PathSelectors.any()) .build() .securitySchemes(Lists.newArrayList(apiKey())) .securityContexts(Arrays.asList(securityContext())); } private ApiKey apiKey() { return new ApiKey("Bearer", "Authorization", "header"); } private SecurityContext securityContext() { return SecurityContext.builder().securityReferences(defaultAuth()) .forPaths(PathSelectors.any()).build(); } private List<SecurityReference> defaultAuth() { AuthorizationScope authorizationScope = new AuthorizationScope( "global", "accessEverything"); AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; authorizationScopes[0] = authorizationScope; return Arrays.asList(new SecurityReference("Bearer", authorizationScopes)); }}但对于每个请求,我的用户都必须输入Bearer 。我可以配置招摇工具,将“Bearer”自动放置在用户插入的 token 之前吗?ks (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 解决此问题的一种方法是将“Bearer”设置为默认值,如下所示 public ResponseEntity method_name(@ApiParam(defaultValue =“Bearer”)字符串身份验证){}此代码将在 token 输入字段框中将“Bearer”显示为默认值。您可以在输入字段框中将 token 添加到承载之后。 (adsbygoogle = window.adsbygoogle || []).push({});
07-24 18:29