我创建了Spring Boot 2 WebFlux应用程序(基于Spring Cloud Gateway项目),现在尝试配置自定义登录页面而不是标准:
@Bean
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
return http.httpBasic().and()
.authorizeExchange()
.anyExchange().authenticated()
.and()
.formLogin().loginPage("/login")
.and()
.csrf().disable()
.build();
}
我尝试使用Thymeleaf通过登录html页面创建和控制器设置来呈现此页面:
@Controller
public class LoginController {
@RequestMapping(value = "/login")
public Mono<String> getLoginPage() {
return Mono.just("/templates/login.html");
}
}
但它不起作用。任何人都可以解释如何做到这一点,我应该使用Thymeleaf吗?也许这已经实现并且在GitHub上?
尝试
@Controller
public class LoginController {
@GetMapping("/login")
public String getLoginPage() {
// assuming that Thymeleaf is present
// and a valid src/main/resources/templates/login.html template
return "login";
}
}