Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 如何使用WebFlux在Spring Boot 2中设置登录页面?_Spring Boot_Spring Security_Thymeleaf_Spring Webflux_Spring Cloud Gateway - Fatal编程技术网

Spring boot 如何使用WebFlux在Spring Boot 2中设置登录页面?

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

我已经创建了Spring Boot 2 WebFlux应用程序(基于Spring云网关项目),现在尝试配置自定义登录页面,而不是标准:

@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包含在应用程序上下文中,但由于某种原因,视图未解析。