springboot+secrity successForwardUrl()不能跳转到界面

 

代码:

@Override
protected void configure(HttpSecurity http) throws Exception {
    //  允许所有用户访问"/"和"/index.html"
    http
            .authorizeRequests()//验证策略策略链
                .antMatchers("/login-success").permitAll()
                .anyRequest().authenticated()
            .and()
            .formLogin()
                .loginPage("/login") //未登录跳转页面,设置了authenticationentrypoint后无需设置未登录跳转
                .loginProcessingUrl("/login")//处理登录post请求接口,无需自己实现
                .successForwardUrl("/index")//登录成功转发接口
               //.defaultSuccessUrl("/hello",true)
                .failureUrl("/login-fail")//登录失败转发接口
                .permitAll()
            .and()
            .logout()//自定义登出
                .logoutUrl("/logout") //自定义登出api,无需自己实现
                .logoutSuccessUrl("/login").permitAll()
            .and()
            .csrf() //跨站
            .disable(); //关闭跨站检测;
}

 登录认证成功,会跳转到successFordwardUrl("/index")设置的index请求.但是,index请求返回的页面访问不到;

解决方法:

不用successFordwardUrl("/index").通过设置defaultSuccessUrl("/hello",true)

你可能感兴趣的:(security)