0

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

4

1 回答 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";
    }
}
于 2018-03-01T14:19:41.457 回答