相关疑难解决方法(0)

如何配置Spring Security以允许无需身份验证即可访问Swagger URL

我的项目有Spring Security.主要问题:无法访问http:// localhost:8080/api/v2/api-docs中的 swagger URL .它表示缺少或无效的授权标头.

浏览器窗口的屏幕截图 My pom.xml包含以下条目

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.4.0</version>
</dependency>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.4.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

SwaggerConfig:

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2).select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build()
            .apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
    ApiInfo apiInfo = new ApiInfo("My REST API", "Some custom description of API.", "API TOS", "Terms of service", "myeaddress@company.com", "License of API", "API license URL");
    return apiInfo;
}
Run Code Online (Sandbox Code Playgroud)

AppConfig的:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.musigma.esp2" })
@Import(SwaggerConfig.class) …
Run Code Online (Sandbox Code Playgroud)

spring-mvc swagger swagger-ui swagger-2.0 springfox

65
推荐指数
8
解决办法
8万
查看次数

标签 统计

spring-mvc ×1

springfox ×1

swagger ×1

swagger-2.0 ×1

swagger-ui ×1