我有带有freemarker模板的SpringBoot应用程序。
MvcConfig:
@Configuration
public class MvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
}
WebSecurityConfig:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder getPaswwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login").permitAll()
.defaultSuccessUrl("/user")
.and()
.rememberMe()
.and()
.logout().permitAll();
}
登录控制器:
@Controller
@RequestMapping
public class LogInController {
@GetMapping("/")
public String greeting(Map<String, Object> model) {
return "redirect:/login";
}
}
当我运行我的应用程序并转到http://localhost:8080/login时,它返回一个异常:
javax.servlet.ServletException:循环视图路径[登录]:将再次分派回当前处理程序URL [/ login]。检查您的ViewResolver设置! (提示:由于默认视图名称的生成,这可能是未指定视图的结果。)
您正在执行递归操作〜
[当您尝试访问http://localhost:8080/login您的端点实现将您重定向到同一位置
Acessing localhost:8090/login => redirect:/login
然后尝试访问相同的URL
Acessing localhost:8090/login => redirect:/login