【问题标题】:Jetty Spring Boot with session replication带有会话复制的 Jetty Spring Boot
【发布时间】:2021-12-22 22:08:00
【问题描述】:

我正在使用带有 Jetty 9.4.43.v20210629 的 spring boot 2.5.3。我想跨多个节点共享会话。在 Jetty 9.4 中,会话管理有很多变化。我想要一些使用 java 配置进行会话复制(使用 JDBC/文件系统)的参考资料。

【问题讨论】:

    标签: spring spring-boot session jetty-9


    【解决方案1】:

    可以使用带有以下存储选项的 spring session 来完成会话复制,

    雾霾 数据库 雷迪斯 MongoDB

    spring.session.store-type 属性应该用于决定存储类型。当多个节点/容器指向同一个存储时,它将共享会话,无需维护粘性会话。

    需要在 pom.xml 中添加适当的依赖,并在需要时添加注解(例如:@EnableJDBCHttpSession)

    示例应用程序 yaml 更改。

    JDBC

    spring:
        application.name: console-bs
        main.allow-bean-definition-overriding: true
        profile: default
        session.store-type: jdbc
        session.jdbc.initialize-schema: always
        jpa.database: mysql
        jpa.database-platform: org.hibernate.dialect.MySQL5Dialect
        datasource.url: jdbc:mysql://mysqldb:3306/user
        datasource.username: user
        datasource.password: user1234#
        datasource.driver-class-name: com.mysql.cj.jdbc.Driver
    

    Redis

    spring:
        application.name: console-bs
        main.allow-bean-definition-overriding: true
        profile: default
        session.store-type: redis
        redis.host: redis
        redis.port: 6379
    

    【讨论】:

    • 在代码块中发布 YAML 会大大提高易读性
    • 编辑了在代码块中发布 YAML 的答案。谢谢
    猜你喜欢
    • 1970-01-01
    • 2019-08-08
    • 2018-01-01
    • 2021-08-20
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 2015-12-23
    • 1970-01-01
    相关资源
    最近更新 更多