前言
解决自定义登录页面,样式图片等丢失问题,根源是SpringSecurity将css、js、image等资源拦截。解除拦截就可以了。
配置
通过配置解决,忽略 Spring Security 对这些资源文件的认证,覆盖 configure(WebSecurity web) 方法,添加忽略路径格式即可。
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/css/**", "/js/**", "/plugins/**", "/images/**", "/fonts/**");
}
还需要配置application.yml文件,指定静态资源。
mvc:
static-path-pattern: /**
view:
prefix: /
resources:
static-locations: ["/static/"]
配置之后,将不再拦截资源下css、js、plugins、images、fonts等文件夹下的所有静态文件。
目录结构如图所示:
启动后界面效果正常,结束!