Spring security排错笔记

spring security 使用过程中,web.ignoring导致默认登录页404

问题

刚接触spring security,参考其他项目无意间写出了如下SecurityConfig类代码(当然,一开始没有这么简单,这是多次调试精简后能复现问题的代码):

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/error","/login");	//忽略这些页面请求的鉴权
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.authorizeRequests()
                .anyRequest().authenticated()	// 所有请求需要身份验证
                .and()
                .formLogin().permitAll();			// 登录页除外
	}
}

运行服务器,访问页面结果如下:

在这里插入图片描述

打开debug日志有如下输出:

2020-02-20 23:44:47.157 DEBUG 15378 — [nio-8081-exec-4] o.s.web.servlet.DispatcherServlet : GET “/login”, parameters={}
2020-02-20 23:44:47.158 DEBUG 15378 — [nio-8081-exec-4] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to ResourceHttpRequestHandler [“classpath:/META-INF/resources/”, “classpath:/resources/”, “classpath:/static/”, “classpath:/public/”, “/”]
2020-02-20 23:44:47.159 DEBUG 15378 — [nio-8081-exec-4] o.s.w.s.r.ResourceHttpRequestHandler : Resource not found
2020-02-20 23:44:47.159 DEBUG 15378 — [nio-8081-exec-4] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND
2020-02-20 23:44:47.160 DEBUG 15378 — [nio-8081-exec-4] o.s.web.servlet.DispatcherServlet : “ERROR” dispatch for GET “/error”, parameters={}
2020-02-20 23:44:47.161 DEBUG 15378 — [nio-8081-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2020-02-20 23:44:47.163 DEBUG 15378 — [nio-8081-exec-4] o.s.w.s.v.ContentNegotiatingViewResolver : Selected ‘text/html’ given [text/html, text/html;q=0.8]
2020-02-20 23:44:47.163 DEBUG 15378 — [nio-8081-exec-4] o.s.web.servlet.DispatcherServlet : Exiting from “ERROR” dispatch, status 404

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值