1
我有一个安全的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页面。我试过创建一个@Configuration
类扩展WebMvcConfigurerAdapter
为了添加一个视图控制器/login
,但这似乎并没有解决它。该课程与我的Application
课程相同。Spring Boot自定义登录页面导致圆形视图路径异常
应用
@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 + "'."));
}
}
}
最小的login.html测试
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>Login</h1>
</body>
</html>
您是否尝试过在登录后设置目标网址以查看它是否会实际重定向到ti? – Aeseir 2014-11-04 01:34:16
不知道该怎么办,因为我甚至无法看到登录页面本身。 – 2014-11-04 12:53:59
啊,所以你实际上看不到登录页面,现在明白了,谢谢澄清。您能否向我们展示login.html页面代码,至少是登录表单的一部分。 – Aeseir 2014-11-04 13:05:11