Java Spring安全自定义登录错误

Java Spring安全自定义登录错误,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,我一直在尝试将SpringSecurity自定义登录(JavaConfig)添加到我的应用程序中,但一个奇怪的错误不断出现 我已经通过了测试,效果很好。我不确定我的申请有什么问题 错误 @Controller public class LoginController { @RequestMapping(value = "login", method = RequestMethod.GET) public String loginView() { return "

我一直在尝试将SpringSecurity自定义登录(JavaConfig)添加到我的应用程序中,但一个奇怪的错误不断出现

我已经通过了测试,效果很好。我不确定我的申请有什么问题

错误

@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";
    }
}
原因:java.lang.IllegalArgumentException:“登录?错误”不是 有效重定向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();
    }
}
登录控制器

@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";
    }
}
只需注释方法
configure(HttpSecurity http)
即可删除异常。我尝试使用值
login?error
添加
RequestMapping
,但没有帮助。我错过了什么


您缺少一条斜线

这:

.loginPage(“登录”)
应该是:

.loginPage(“/login”)

好吧,斜杠被省略了,因为我的控制器有一个“login”的
RequestMapping
,而不是“/login”@ItachiUchiha
@RequestMapping
值也应该以
/
开头。这是必须的吗?在添加spring安全性之前,没有
/