繁体   English   中英

Spring Boot + Spring Security 的自定义登录页面

[英]Custom Login Page for Spring Boot + Spring Security

下面是我的配置。 我导航到http://localhost:8080并重定向到http://localhost:8080/bruceLogin这是预期的。 但我的页面显示“白标错误页面。此应用程序没有明确的 /error 映射,因此您将其视为后备……”。 请注意,我确实在 src/main/resources/template 下有一个名为 bruceLogin1.html 的简单 html 页面。 知道我在这里缺少什么吗?

*旁注:令人遗憾的是,spring boot 没有为开发人员提供一种机制来仅使用属性文件来配置自定义登录页面。

@SpringBootApplication
@EnableWebSecurity
public class SpringSecurityCatalogApplication  implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(SpringSecurityCatalogApplication.class, args);
    }


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/bruceLogin").setViewName("bruceLogin1");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }

    @EnableWebSecurity
    @Order(Ordered.HIGHEST_PRECEDENCE)
    class SecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {

             http
             .authorizeRequests()
             .antMatchers("/resources/**").permitAll()
             .anyRequest().authenticated()
             .and()
             .formLogin()
             .loginPage("/bruceLogin")
             .permitAll();
        }
    }
}

解决方案:在我的 build.gradle 中添加 implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 后,此问题已解决。 感谢范泰盛的建议

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM