How to create/enable sticky sessions in Spring Boot

522 Views Asked by At

As I'm working on a vaadin project, I need sticky sessions for session replication. Otherwise, it won't work. I'm using JDBC to store the session. But since it's not sticky yet, the website keeps refreshing when starting the app. I know it has something to do with the load balancer. But since I'm a total beginner I have no idea how to access it and set custom configurations.

This is my properties file

server.port=${PORT:8080}
logging.level.org.atmosphere = warn
spring.mustache.check-template-location = false
spring.session.jdbc.initialize-schema= embedded
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driverClassName=org.h2.Driver
spring.session.jdbc.table-name=SPRING_SESSION
spring.h2.console.path=/h2
spring.h2.console.enabled=true
spring.session.store-type=jdbc
spring.datasource.url=jdbc:h2:~/sessions
spring.datasource.username=xx
spring.datasource.password=xx
vaadin.launch-browser=true

And here are my dependencies

<dependencies>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
    </dependencies>
0

There are 0 best solutions below