Problem discovery
The springboot project produces session-out timeout problem. Describe the problem:
Configure session-out in the test environment by changing application.yaml, and verify the session-out by setting different times. The out configuration took effect, so the expiration time was directly set to 8 hours and released to the production environment. However, I received customer feedback at noon that the project expiration time was set to be short. If no operation is performed for half an hour, the session will expire and require repeated login.
Solution
Development environment: The springboot project has built-in Tomcat, so the session-out configured in application.yaml in the project is effective.
Production environment: The production environment is released through cloud services (Docker K8s) and Docker to build images. However, the session-out in the web.xml of the basic image tomacat is set to 30 minutes.
Solution: Finally, when Docker builds the image, put the modified web.xml into the DockerFile, overwrite the original web.xml of the base image, and build the image again to successfully replace the web.xml of the original base image. Problem It was eventually resolved.
Seesion invalidation: Create a session from the time the user logs in. When the user stops operating for longer than the session-out setting time, the session expires.
1. Set in the project's web.xml
[html] view plain copy<!-- 时间单位为分钟 --> <session-config> <session-timeout>15</session-timeout></session-config>
2. Set in the web container (here, tomcat is used as an example)
[html] view plain copy <!-- ==================== Default Session Configuration ================= --> <!-- You can set the default session timeout (in minutes) for all newly --> <!-- created sessions by modifying the value below. --> <session-config> <session-timeout>30</session-timeout> </session-config>
3. Set through Java code
session.setMaxInactiveInterval(30*60);//以秒为单位
4.springboot project application.yaml settings
server: port: 8089 session: timeout: 1800 #以秒为单位
5.Copy web.xml to DockerFile
COPY ./web.xml /opt/tpapp/tomcat/conf
The above is the detailed content of How to set session timeout in SpringBoot Session. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment