无法使Swagger ui与springboot一起使用,得到白色标签错误(403)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法使Swagger ui与springboot一起使用,得到白色标签错误(403)相关的知识,希望对你有一定的参考价值。
你好,我一直在尝试为我的spring-boot项目设置swagger,但是当我在本地主机中打开端口8080打开swagger api时出现白色标签错误
This is the error I get in my browser when I enter http://localhost:8080/swagger-ui.html
我pom.xml
中的招摇依赖项:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
SwaggerConfig
类:
public class SwaggerConfig
private static final String SWAGGER_API_VERSION = "1.0";
private static final String LICENSE_TEXT = "License";
private static final String title = "Inhalo REST API";
private static final String description = "RESTful API for Inhalo";
private ApiInfo apiInfo()
return new ApiInfoBuilder()
.title(title)
.description(description)
.license(LICENSE_TEXT)
.version(SWAGGER_API_VERSION)
.build();
@Bean
public Docket productsApi()
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.pathMapping("/")
.select()
.paths(PathSelectors.regex("/api.*"))
.build();
这是我的WebSecurity
类:
private static final String[] AUTH_WHITELIST =
// -- swagger ui
"/v2/api-docs",
"/swagger-resources",
"/swagger-resources/**",
"/configuration/ui",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**"
// other public endpoints of your API may be appended to this array
;
@Override
protected void configure(HttpSecurity http) throws Exception
http.cors().and().csrf().disable().authorizeRequests()
.antMatchers(HttpMethod.POST, SecurityConstants.SIGN_UP_URL).permitAll()
.antMatchers(SecurityConstants.MEDICINE_ALL, String.valueOf(AUTH_WHITELIST)).permitAll()
.anyRequest().authenticated()
.and()
.addFilter(new JWTAuthenticationFilter(authenticationManager()))
.addFilter(new JWTAuthorizationFilter(authenticationManager()))
// this disables session creation on Spring Security
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
我尝试了各种选项,但仍然收到相同的白标错误
答案
您解决了这个问题吗?我也面临着。
以上是关于无法使Swagger ui与springboot一起使用,得到白色标签错误(403)的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot整合Swagger-ui快速生成在线API文档
无法从 spring-boot 应用程序中调出 swagger-ui