我已经创建了Spring Boot2 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上实现了?
发布于 2018-03-01 22:19:41
试一试
@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";
}
}https://stackoverflow.com/questions/49050584
复制相似问题