我正在使用安全性进行Spring Boot,我想拥有自定义的登录页面,成功登录后,我想打开仪表板页面。
在我的代码中,成功登录后,我使用了默认登录页面,它不会重定向到仪表板页面。
我尝试了多种方法,但是没有运气。
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/resources/**", "/register").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().defaultSuccessUrl("/dashboard", true)
// .loginPage("/login")
.permitAll()
.and()
.logout().logoutSuccessUrl("/login")
.permitAll();
}
}
WebMvcConfigurer
@EnableWebMvc
@ComponentScan("com.hrmanagement")
public class WebMvcConfiguration implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// registry.addViewController("/loginPage").setViewName("login");
registry.addViewController("/dashboard").setViewName("login");
// registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}
}
成功登录后,它将重定向到http://localhost:8080/dashboard
我明白了
白标错误页面
此应用程序没有针对/ error的显式映射,因此您将其视为后备。
2019年3月10日星期日17:14:47 发生意外错误(类型=未找到,状态= 404)。 没有可用的消息。
我尝试过,在多个位置(静态,模板文件夹,然后添加webapp-views)添加登录页面,但是没有运气,请有人提出建议或帮助我更好地理解。