Spring 不支持GET方法,登录成功后显示,如何解决?

Spring 不支持GET方法,登录成功后显示,如何解决?,spring,spring-boot,spring-security,thymeleaf,Spring,Spring Boot,Spring Security,Thymeleaf,我正在开发一个管理系统,我有HomeController.java: @Controller public class HomeController { @Autowired private UserRepository userRepository; @Autowired private UserService userService; @GetMapping("/") public String root() { ret

我正在开发一个管理系统,我有HomeController.java:

@Controller
public class HomeController {


    @Autowired
    private UserRepository userRepository;
    @Autowired
    private UserService userService;


    @GetMapping("/")
    public String root() {
        return "/home";
    }


    @GetMapping("/home")
    public String home() {
        return "/home";
    }


    @RequestMapping("/login")
    public String login() {
        return "/login";
    }

    @RequestMapping("/user")
    public String userIndex() {
        return "/index";
    }


    @GetMapping("/profile")
    public String currentUser(@ModelAttribute("user") @Valid UserDto userDto, BindingResult result, Model model) {

        Authentication loggedInUser = SecurityContextHolder.getContext().getAuthentication();
        String email = loggedInUser.getName();


        User user = userRepository.findByEmail(email);
        String firstName = user.getFirstName();
        model.addAttribute("firstName", firstName);
        model.addAttribute("email", email);


        return "profile";

    }
当我尝试使用错误的凭据登录时,一切正常,并给出无效的密码或用户名。 问题是,当我输入正确的凭据时,我会得到以下页面:

以下是SecurityConfig.java:

@Configuration

public class SecurityConfig extends WebSecurityConfigurerAdapter {


    @Autowired
    private UserService userService;


    @Autowired
    private UserRepository userRepository;


    @Override
    protected void configure(final HttpSecurity http) throws Exception {
        // @formatter:off


        http
                .authorizeRequests()
                .antMatchers(
                        "/"
                        , "/home"
                        , "/registration"
                        , "/forgot-password/"
                        , "/reset-password/"
                        , "/welcome"
                        , "/js/**"
                        , "/css/**"
                        , "/img/**"
                        , "/webjars/**"


                )
                .permitAll()

                .and()
                .authorizeRequests()
                .antMatchers("/admin/**").hasRole("ADMIN")
                .antMatchers("/super/**").hasRole("SUPER")
                .antMatchers("/partner/**").hasRole("PARTNER")
                .anyRequest()
                .authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .defaultSuccessUrl("/index" , true)
                .permitAll()
                .and()
                .logout()
                .invalidateHttpSession(true)
                .clearAuthentication(true)
                .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                .logoutSuccessUrl("/login?logout")
                .permitAll()
                .and()
                .rememberMe()
                .and()
                .rememberMe()
                .key("uniqueAndSecret")
                .userDetailsService(userService);

    }


    //Beans
    @Bean
    public PasswordEncoder encoder() {
        return new BCryptPasswordEncoder(11);
    }

    @Bean
    public DaoAuthenticationProvider authenticationProvider() {
        DaoAuthenticationProvider auth = new DaoAuthenticationProvider();
        auth.setUserDetailsService(userService);
        auth.setPasswordEncoder(encoder());
        return auth;
    }


    @Bean
    public AuthenticationManager customAuthenticationManager() throws Exception {
        return authenticationManager();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(authenticationProvider());
    }
}

此处:

@RequestMapping(“/user”)
公共字符串userIndex(){
返回“/索引”;
}

您确实重定向到索引(不带“.html”扩展名),但没有
index
url的映射。 因此,您可以将其更改为:
return”/index.html”

如果静态目录中有
index.html
文件。

此处:

@RequestMapping(“/user”)
公共字符串userIndex(){
返回“/索引”;
}

您确实重定向到索引(不带“.html”扩展名),但没有
index
url的映射。 因此,您可以将其更改为:
return”/index.html”


如果您在静态目录中有
index.html
文件。

没有将
/index
映射到
index.html
。您的请求将发送到
/index
。您没有映射到
/index
/的端点不是@ReuestMappin(“/user”)公共字符串userIndex(){return”/index”}索引端点的映射吗?我要做的是,如果你有资源来解释这一点,请提供它!没有将
/index
映射到
index.html
。您的请求将发送到
/index
。您没有映射到
/index
/的端点不是@ReuestMappin(“/user”)公共字符串userIndex(){return”/index”}索引端点的映射吗?我要做的是,如果你有资源来解释这一点,请提供它!