我想将会话数据保存在springcloud网关过滤器的后台,但无法获取。此外,每次生成新会话时,都可以使用会话将数据保存在Filter中。
@Component("LoginFilter")
public class LoginFilter implements GlobalFilter, Ordered {
private static final Logger logger = LoggerFactory.getLogger(LoginFilter.class);
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
exchange.getSession().map(
session -> {
session.getAttribute("foo");
session.getAttributes().put("foo", "bar");
return session;
}
);
return chain.filter(exchange);
}
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
}