Java 如何使用spring security在主页之前先显示登录页面?

Java 如何使用spring security在主页之前先显示登录页面?,java,hibernate,spring-mvc,spring-security,Java,Hibernate,Spring Mvc,Spring Security,我需要在首页之前显示登录页面。若用户的用户名和密码正确,那个么我需要转到主页。但在这个程序中,主页首先显示,当我键入“/login”时,只显示登录页面。 如何首先显示登录页面,在用户身份验证后,需要显示主页 这是我在安全配置类中的代码。我跳过了其他部分,因为只有从这里开始处理程序 protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antM

我需要在首页之前显示登录页面。若用户的用户名和密码正确,那个么我需要转到主页。但在这个程序中,主页首先显示,当我键入“/login”时,只显示登录页面。 如何首先显示登录页面,在用户身份验证后,需要显示主页

这是我在安全配置类中的代码。我跳过了其他部分,因为只有从这里开始处理程序

protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
        .antMatchers("/home").access("hasRole('User')")
        .and()
        .formLogin().loginPage("/login").defaultSuccessUrl("/home")
        .usernameParameter("username").passwordParameter("password")
        .and()
        .csrf()
        .and()
        .exceptionHandling().accessDeniedPage("/accessDenied");
    }
这是我的控制器类

@Controller
public class LoginController {

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String loginPage(ModelMap model,
            @RequestParam(value = "logout", required = false) String logout,
            @RequestParam(value = "error", required = false) String error) {

        return "login";
    }

    @RequestMapping(value = {"/","/home"}, method = RequestMethod.GET)
    public String homePage(ModelMap model) {
        model.addAttribute("greeting", "Hi, Welcome to mysite");
        return "welcome";
    }

    @RequestMapping(value = "/accessDenied", method = RequestMethod.GET)
    public String loginPage() {
        return "accessDenied";
    }
}

我怀疑您正在访问URL
/
下的主页。登录要求仅适用于
/home

.antMatchers("/home").access("hasRole('User')")

您能告诉我如何使用安全性在spring应用程序开始时将url从更改为吗?我总是在申请之初就开始学习。