我想使用spring security进行身份验证和授权......但是我遇到了问题...登录页面无法正确加载!... 我不知道应该用什么来代替“登录”?
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll();
RenderController.java
@Controller
@RequestMapping("/")
public class RenderController {
@Autowired
private HRMUserService userService;
@RequestMapping(method = RequestMethod.GET)
public String getIndexPage() {
return "login";
}
@RequestMapping(value = "login", method = RequestMethod.POST)
public String login(HttpServletRequest request, @RequestParam String username, @RequestParam String password,
@Valid @ModelAttribute("userForm") HRMUser userForm, BindingResult result) {
return "index";
}
这个项目是单页面Web应用程序,有两个页面:索引和登录。 它没有身份验证和授权就可以正常工作但是在添加这些功能后我遇到了loginPage的问题...当我使用loginPage(“/ login”)时我收到此错误:
HTTP状态405 - 不支持请求方法“GET”
当我使用.loginPage(“/ index”)
时HTTP状态404 -
当我使用.loginPage(“/”)时 页面加载,但css和js无法识别!
答案 0 :(得分:0)
您需要使用RequestMethod.GET为登录页面添加映射。这样的事情:
@RequestMapping(value = "login", method = RequestMethod.GET)
public String getLoginPage() {
return "login";
}