[英]Custom Login Page for Spring Boot + Spring Security
Below is my configuration.下面是我的配置。 I navigate to http://localhost:8080 and is redirected to http://localhost:8080/bruceLogin which is expected.我导航到http://localhost:8080并重定向到http://localhost:8080/bruceLogin这是预期的。 But i got page displaying "Whitelabel Error Page. This application has no explicit mapping for /error, so you are seeing this as a fallback...".但我的页面显示“白标错误页面。此应用程序没有明确的 /error 映射,因此您将其视为后备……”。 Note I did have a simple html page called bruceLogin1.html under src/main/resources/template.请注意,我确实在 src/main/resources/template 下有一个名为 bruceLogin1.html 的简单 html 页面。 Any idea what i am missing here?知道我在这里缺少什么吗?
*Side Note: One sad thing is that spring boot does not provide a mechanism for developer to configure the custom login page using solely properties file. *旁注:令人遗憾的是,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();
}
}
}
Solution: This issue is resolved after I add implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' to my build.gradle.解决方案:在我的 build.gradle 中添加 implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 后,此问题已解决。 Thanks to Pham Thai Thinh for the suggestion感谢范泰盛的建议
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.