I am using spring boot 2.5.3 with Jetty 9.4.43.v20210629. I want to share the session across multiple nodes. In Jetty 9.4 there are lot of changes in session management. I want some reference materials for session replication (using JDBC / File system) with java configurations.
CodePudding user response:
Session replication can be done using spring session with following storage options,
Hazlecast Database Redis MongoDB
spring.session.store-type property should be used to decide the storage type. When multiple nodes / containers point to same storage it will share the session and no need to maintain a sticky session.
Need to add proper dependencies in pom.xml and add annotations when required (ex: @EnableJDBCHttpSession)
sample application yaml changes.
JDBC
spring: application.name: vrm-dvr-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: vrm-dvr-console-bs main.allow-bean-definition-overriding: true profile: default session.store-type: redis redis.host: redis redis.port: 6379