Spring Security自定义登录错误

Ita*_*iha 10 java spring spring-mvc spring-security

我一直在尝试将Spring Security Custom Login(Java Config)添加到我的应用程序中,但是一个奇怪的错误不断出现.

我已经完成了创建自定义登录表单教程,它工作得很好.我不确定我的申请是什么问题.

错误

引起:java.lang.IllegalArgumentException:'login?error'不是有效的重定向URL

安全配置

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    public void configure(AuthenticationManagerBuilder auth)
            throws Exception {
        auth
        .inMemoryAuthentication()
            .withUser("user").password("password").roles("USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/", "/about").permitAll();
        http
        .authorizeRequests()
        .antMatchers("/admin","/admin/**").hasRole("ADMIN")
        .anyRequest().authenticated()
        .and()
        .formLogin()
        .loginPage("login")
        .permitAll();
    }
}
Run Code Online (Sandbox Code Playgroud)

的LoginController

@Controller
public class LoginController {

    @RequestMapping(value = "login", method = RequestMethod.GET)
    public String loginView() {
        return "login";
    }

    @RequestMapping(value = "login", method = RequestMethod.POST)
    public String login(@ModelAttribute Login login) {
        return "home";
    }
}
Run Code Online (Sandbox Code Playgroud)

只需注释该方法即可configure(HttpSecurity http)删除该异常.我尝试添加RequestMapping有价值login?error,但它没有帮助.我在这里错过了什么?

链接到完整的堆栈跟踪

hol*_*s83 19

你错过了一个斜线.

这个:

.loginPage("login")
Run Code Online (Sandbox Code Playgroud)

应该:

 .loginPage("/login")
Run Code Online (Sandbox Code Playgroud)