【问题标题】:Change session cookie name and path in Spring Boot WebFlux在 Spring Boot WebFlux 中更改会话 cookie 名称和路径
【发布时间】:2020-05-26 00:18:17
【问题描述】:

我正在使用 WebFlux 创建一个响应式 Spring Boot 项目。我需要配置会话cookie名称和路径。

在基于 Tomcat 的项目中,configure the session cookie using the configuration 文件很容易:

server.servlet.session.cookie.name = MYSESSIONID
server.servlet.session.cookie.path = /

如果我在 WebFlux 项目中配置这些属性,它不会影响 cookie 参数。该怎么做?

【问题讨论】:

  • 正如您在属性中看到的,它说“servlet”webflux 不使用 servlet。
  • 没错,这正是我要问的原因。 WebFlux 中的等效配置是什么。
  • 没有,webflux用的是netty,你得在netty里查一下怎么弄,我答不上来

标签: spring spring-boot session-cookies spring-webflux reactive


【解决方案1】:

如果您碰巧使用 Spring Session,您可以为 WebSessionIdResolver 创建自己的 bean,它设置会话 cookie 的名称(和其他属性)。

@Configuration
public class CookieConfig {

    @Bean
    public WebSessionIdResolver webSessionIdResolver() {
        CookieWebSessionIdResolver resolver = new CookieWebSessionIdResolver();
        resolver.setCookieName("MYSESSIONID");
        return resolver;
    }

}

Spring Session 指南在 Spring Session - WebFlux with Custom Cookie 中对此进行了介绍。

【讨论】:

  • 我还需要添加 @EnableSpringWebSession 和一个 ReactiveSessionRepository bean
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-05
  • 2020-07-24
  • 1970-01-01
  • 2021-08-31
  • 1970-01-01
  • 2021-02-25
相关资源
最近更新 更多