老师好,我做spring security in action项目时按照您的配置访问/index目录时报错
来源:11-5 -Spring Security 实战-前台编码
慕函数2389585
2017-09-05
would dispatch back to the current handler URL [/index] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)这个错误,我试过该映射路径为类似/toIndex这类的,但是之后又报了404我不清楚要怎么改
//我的security配置
package com.huidi.spring.boot.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/*
* 安全配置类
* */
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true) // 启用方法安全设置
public class SecurityConfig extends WebSecurityConfigurerAdapter{
/*
* 认证信息管理
* @param auth
* @throws Exception
* */
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)throws Exception{
auth.inMemoryAuthentication()//存于内存
.withUser("wanghuidi").password("123456").roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception{
http.authorizeRequests()
.antMatchers("/css/**","/js/**","/fonts/**","/index").permitAll()
.antMatchers("/users/**").hasRole("ADMIN")
.and()
.formLogin()
.loginPage("/login").failureUrl("/login-error");
}
}
//MainController
package com.huidi.spring.boot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/*
* 主页控制器
* */
@Controller
public class MainController {
@GetMapping("/")
public String root(){
return "redirect:/index";
}
@GetMapping("/index")
public String index(){
return "index";
}
@GetMapping("/login")
public String login(){
return "login";
}
@GetMapping("/login-error")
public String loginError(Model model){
model.addAttribute("loginError",true);
model.addAttribute("errorMsg","登录失败,用户名或密码错误!");
return "login";
}
}
//我的包结构
1回答
-
老卫
2017-09-05
看错误,应该是页面解析错误。看下你login页面的模型,是否解析有问题
00
基于Spring Boot技术栈博客系统企业级前后端实战
1296 学习 · 738 问题
相似问题