search
HomeJavajavaTutorialHow to set session timeout in SpringBoot Session

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!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

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

How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PM

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

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

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

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PM

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]

How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

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

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment