小编Has*_*son的帖子

如何在Spring boot rest应用程序中使用Swagger ui使用密码流配置oAuth2

我有使用另一个Spring启动授权服务器的spring boot rest api(资源),我已经将Swagger配置添加到资源应用程序,以便为其余的API获得一个漂亮而快速的文档/测试平台.我的Swagger配置如下所示:

@Configuration
@EnableSwagger2
public class SwaggerConfig {    

    @Autowired
    private TypeResolver typeResolver;

    @Value("${app.client.id}")
    private String clientId;
    @Value("${app.client.secret}")
    private String clientSecret;
    @Value("${info.build.name}")
    private String infoBuildName;

    public static final String securitySchemaOAuth2 = "oauth2";
    public static final String authorizationScopeGlobal = "global";
    public static final String authorizationScopeGlobalDesc = "accessEverything";

    @Bean
    public Docket api() { 

        List<ResponseMessage> list = new java.util.ArrayList<ResponseMessage>();
        list.add(new ResponseMessageBuilder()
                .code(500)
                .message("500 message")
                .responseModel(new ModelRef("JSONResult«string»"))
                .build());
        list.add(new ResponseMessageBuilder()
                .code(401)
                .message("Unauthorized")
                .responseModel(new ModelRef("JSONResult«string»"))
                .build());


        return new Docket(DocumentationType.SWAGGER_2)  
          .select()                                  
          .apis(RequestHandlerSelectors.any())              
          .paths(PathSelectors.any())     
          .build()
          .securitySchemes(Collections.singletonList(securitySchema())) …
Run Code Online (Sandbox Code Playgroud)

java swagger swagger-ui spring-boot springfox

10
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×1

spring-boot ×1

springfox ×1

swagger ×1

swagger-ui ×1