Spring boot 如何使用WebFlux在Spring Boot 2中设置登录页面?
我已经创建了Spring Boot 2 WebFlux应用程序(基于Spring云网关项目),现在尝试配置自定义登录页面,而不是标准:Spring boot 如何使用WebFlux在Spring Boot 2中设置登录页面?,spring-boot,spring-security,thymeleaf,spring-webflux,spring-cloud-gateway,Spring Boot,Spring Security,Thymeleaf,Spring Webflux,Spring Cloud Gateway,我已经创建了Spring Boot 2 WebFlux应用程序(基于Spring云网关项目),现在尝试配置自定义登录页面,而不是标准: @Bean SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) { return http.httpBasic().and() .authorizeExchange() .anyExchange().authenticat
@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");
}
}
@控制器
公共类登录控制器{
@请求映射(value=“/login”)
公共Mono getLoginPage(){
返回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";
}
}
谢谢你的回复。这有助于解决问题。但现在我不明白为什么这个观点没有得到解决。由于某种原因,应用程序上下文不包含Thymeleaf视图解析器。更准确地说,Thymeleaf bean包含在应用程序上下文中,但由于某种原因,视图未解析。