springboot拦截html页⾯元素,SpringBoot+SpringSecurit。。
⼀、问题描述
在 SpringBoot 中加⼊ SpringSecurity 中之后,静态资源总是被过滤,导致界⾯很难看:
⽬录结构:
⼆、问题解决
正常不拦截资源,我查阅资料,基本都是重新 config ⽅法即可:
fig;
import t.annotation.Bean;
springboot结构
import t.annotation.Configuration;
import org.fig.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.fig.annotation.web.builders.HttpSecurity;
import org.fig.annotation.web.builders.WebSecurity;
import org.fig.figuration.WebSecurityConfigurerAdapter;
import org.pto.password.NoOpPasswordEncoder;
import org.pto.password.PasswordEncoder;
/**
* @Auther: Yolo
* @Date: 2020/9/12 13:05
* @Description:
*/
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
PasswordEncoder passwordEncoder() {
Instance();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception { //在内存中进⾏配置
auth.inMemoryAuthentication()
.withUser("yolo")
.password("123").roles("admin");
}
@Override
public void configure(WebSecurity web) throws Exception {
//web.ignoring().antMatchers("/static/js/**", "/static/css/**", "/static/images/**"); web.ignoring().antMatchers("/js/**", "/css/**","/images/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login.html")
.permitAll()//跟登录相关的页⾯统统放⾏
.and()
.csrf().disable()
;
}
}
常规⽅法是:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/js/**", "/css/**","/images/**");
}
这⾥⼀定要谨记,这样配置了 configure,之后,⼀定要清除 target,不然是不会⽣效的
到此这篇关于SpringBoot+SpringSecurity 不拦截静态资源的实现的⽂章就介绍到这了,更多相关SpringBoot+SpringSecurity 不拦截静态资源内容请搜索WEB开发者以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持WEB开发者!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。