问题描述:
使用的springboot版本是2.3.12.RELEASE,引用的依赖如下:
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.10.5</version>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.22</version>
</dependency>
在WebSecurityConfigurerAdapter继承类当中配置了跳过认证
@Override
public void configure(WebSecurity web) {
web.ignoring().antMatchers("/doc.html",
"/favicon.ico",
"/v2/api-docs",
"/swagger-resources/**",
"/webjars/**");
}
然后访问doc.html接口文档也可以正常访问,就是每访问一次控制台就会出来一个异常,后来排查到访问doc.html的时候他会去访问http://localhost:9079/stdc/api/talentpool/favicon.ico
,是这个接口报出来的异常。
/stdc/api/talentpool是设置的
server.servlet.context-path
这个异常是由自定义的认证失败类 抛出来的。按正常来说就算认证失败了request.getRequestURI()获取到的也不应该是error呀。
解决过程:
针对于这个问题其实官网当中是有提到的:https://gitee.com/xiaoym/knife4j/issues/I3UEMQ
favicon.ico就是获取的网站的图标,在当前工程下,resources/static目录下存放一个favicon.ico文件即可解决。