Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Spring引导自定义登录页导致循环视图路径异常_Angularjs_Spring_Spring Mvc - Fatal编程技术网

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

Angularjs Spring引导自定义登录页导致循环视图路径异常,angularjs,spring,spring-mvc,Angularjs,Spring,Spring Mvc,我有一个具有以下配置类的安全Spring引导应用程序。当我浏览我的应用程序时,我被重定向到/login,但是服务器抛出一个servlet异常,消息是循环视图路径[login]:将再次发送回当前处理程序URL[/login]。我的应用程序是AngularJS应用程序,因此没有服务器端视图渲染。我在/src/main/resources/static中有一个login.html页面。我试图创建一个扩展WebMVCConfigureAdapter的@Configuration类,以便为/login添加

我有一个具有以下配置类的安全Spring引导应用程序。当我浏览我的应用程序时,我被重定向到
/login
,但是服务器抛出一个servlet异常,消息是
循环视图路径[login]:将再次发送回当前处理程序URL[/login]。
我的应用程序是AngularJS应用程序,因此没有服务器端视图渲染。我在/src/main/resources/static中有一个login.html页面。我试图创建一个扩展
WebMVCConfigureAdapter
@Configuration
类,以便为
/login
添加一个视图控制器,但这似乎无法解决问题。该类与我的
应用程序
类位于同一个包中

应用程序

@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

@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
重命名为其他名称时,问题似乎得到了解决,比如
loginpage.html
。显然,到视图的路径与静态页面的url相混淆。

您是否尝试在登录后设置目标url,以查看它是否确实会重定向到ti?不确定这将做什么,因为我甚至看不到登录页面本身。啊,所以您实际上看不到登录页面,现在明白了,谢谢澄清。你能给我们看login.html页面代码吗,至少是它的登录表单部分。当然,但现在它是一个非常小的页面,甚至没有表单。我只是想在创建表单之前让它显示出来。