首页 > 解决方案 > 在 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,但我没有看到授权按钮或我的应用信息。我可能错过了什么?

标签: spring-bootswaggerswagger-ui

解决方案


推荐阅读