pch205090 2021-12-31 10:19 采纳率: 100%
浏览 116
已结题

springboot整合springsecurity 自定义登录界面 静态资源被重定向

使用springboot整合springsecurity自定义登录界面 发现自定义界面的静态资源没加载进来 浏览器报302

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private LoginUserDetailsService LUDS;
@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
            .antMatchers("/css/**,/js/**,/img/**").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .successForwardUrl("/main_home")
            .permitAll().and().csrf().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(LUDS).passwordEncoder(password());
}

@Bean
PasswordEncoder password(){
    return new BCryptPasswordEncoder();
}

}

浏览器控制台报错代码
login:1 Refused to apply style from 'http://localhost:25080/login' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
login:1 Refused to apply style from 'http://localhost:25080/login' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
login:1 Refused to execute script from 'http://localhost:25080/login' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
login:1 Refused to execute script from 'http://localhost:25080/login' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
login:1 Refused to execute script from 'http://localhost:25080/login' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
login:1 Refused to apply style from 'http://localhost:25080/login' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
login:1 Refused to apply style from 'http://localhost:25080/login' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
出错代码302

  • 写回答

3条回答 默认 最新

  • CSDN专家-微编程 2021-12-31 10:56
    关注

    不是你这样写的呀,你要对每个静态资源分开写,然后逗号隔开,你这样写人家识别不了的

    img


    正确如下

    .antMatchers("/css/**","/js/**","/images/**").permitAll()
    

    如有帮助,望采纳一下,谢谢

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 1月9日
  • 已采纳回答 1月1日
  • 创建了问题 12月31日

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题