Spring boot cloud gateway and keycloak 401 error

Hi All

Hopefully someone will be able to point me in the right direction. I am working on a spring boot microservices project using keycloak to authenticate users.

The spring boot service gateway is able to interact with keycloak and login to the application. After a period of inactivity. The gateway returns a HTTP 401 response to the client, is it possible to redirect the user back to the keycloak login page when this happens.

The Security Configuration for the service gateway is as follows.

public class SecurityConfig {

public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
            .authorizeExchange(exchanges -> exchanges                
    return http.build();