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

问题描述 投票:0回答:1

我创建了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上?

spring-boot spring-security thymeleaf spring-webflux spring-cloud-gateway
1个回答
1
投票

尝试

@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";
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.