出现/favicon.ico访问404、网页图标不更新、成功登录后出现404等问题,做了各种尝试。在如下环境解决方法
环境: spring boot + spring security+ thymeleaf
解决方法:
1.favicon.ico文件放在项目的/resources/static目录下
2.自定义的WebSecurityConfigurerAdapter类中
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"/resources/**",
"/static/**",
"/css/**",
"/ajax/**",
"/fonts/**",
"/img/**",
"/js/**",
"/login/**",
"/webjars/**",
"/error/**"
};
/**
* 放行静态资源
*/
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(CLASSPATH_RESOURCE_LOCATIONS);
}
- 不需要在上面类中添加“/favicon.ico"的登录放行配置
@Override
public void configure(HttpSecurity http) throws Exception {
//解决非thymeleaf的form表单提交被拦截问题
http.csrf().disable();
http.authorizeRequests() //授权
- 不需要在application.yml中做任何配置
- 引用的html文件中必须添加,否则还是404错误
<link rel="Bookmark" type="image/x-icon" th:href="@{/static/favicon.ico}">
<link rel="icon" type="image/x-icon" th:href="@{/static/favicon.ico}">
<link rel="shortcut icon" type="image/x-icon" th:href="@{/static/favicon.ico}">
.