Spring Boot自定义登录页面导致循环视图路径异常

时间:2014-11-04 00:51:07

标签: angularjs spring spring-mvc

我有一个安全的Spring Boot应用程序,其中包含以下配置类。当我浏览到我的应用程序时,我被重定向到/login,但服务器抛出一个servlet异常,消息为Circular view path [login]: would dispatch back to the current handler URL [/login] again.我的应用程序是一个AngularJS应用程序,所以没有服务器端视图呈现。我有一个位于/ src / main / resources / static的login.html页面。我尝试创建一个@ConfigurationWebMvcConfigurerAdapter来扩展/login,以便为Application添加一个视图控制器,但这似乎并没有解决它。该类与我的@Configuration @EnableAutoConfiguration @Import({CommonsJpaConfig.class}) @ComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 类位于同一个包中。

应用

@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                    .anyRequest().authenticated();

        http
                .formLogin()
                    .loginPage("/login")
                    .permitAll()
                    .and()
                .logout()
                    .permitAll();
    }

    @Configuration
    protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {

        @Inject
        private PersonRepository personRepository;

        @Override
        public void init(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(userDetailsService());
        }

        @Bean
        public UserDetailsService userDetailsService() {
            return (email) -> personRepository.findByEmail(email)
                    .orElseThrow(() -> new UsernameNotFoundException("Could not find the user with email '" + email + "'."));
        }
    }
}

安全配置

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<h1>Login</h1>
</body>
</html>

用于测试的最小login.html

{{1}}

1 个答案:

答案 0 :(得分:0)

对我来说,当我将login.html重命名为其他内容时,问题似乎已得到解决,例如loginpage.html。显然,视图的路径与静态页面的URL混淆。