How to set session timeout in SpringBoot Session
May 15, 2023 pm 02:37 PMProblem 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<!-- 時(shí)間單位為分鐘 -->??<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!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

1. Redis implements distributed lock principle and why distributed locks are needed. Before talking about distributed locks, it is necessary to explain why distributed locks are needed. The opposite of distributed locks is stand-alone locks. When we write multi-threaded programs, we avoid data problems caused by operating a shared variable at the same time. We usually use a lock to mutually exclude the shared variables to ensure the correctness of the shared variables. Its scope of use is in the same process. If there are multiple processes that need to operate a shared resource at the same time, how can they be mutually exclusive? Today's business applications are usually microservice architecture, which also means that one application will deploy multiple processes. If multiple processes need to modify the same row of records in MySQL, in order to avoid dirty data caused by out-of-order operations, distribution needs to be introduced at this time. The style is locked. Want to achieve points

1. Customize RedisTemplate1.1, RedisAPI default serialization mechanism. The API-based Redis cache implementation uses the RedisTemplate template for data caching operations. Here, open the RedisTemplate class and view the source code information of the class. publicclassRedisTemplateextendsRedisAccessorimplementsRedisOperations, BeanClassLoaderAware{//Declare key, Various serialization methods of value, the initial value is empty @NullableprivateRedisSe

Springboot reads the file, but cannot access the latest development after packaging it into a jar package. There is a situation where springboot cannot read the file after packaging it into a jar package. The reason is that after packaging, the virtual path of the file is invalid and can only be accessed through the stream. Read. The file is under resources publicvoidtest(){Listnames=newArrayList();InputStreamReaderread=null;try{ClassPathResourceresource=newClassPathResource("name.txt");Input

SpringBoot and SpringMVC are both commonly used frameworks in Java development, but there are some obvious differences between them. This article will explore the features and uses of these two frameworks and compare their differences. First, let's learn about SpringBoot. SpringBoot was developed by the Pivotal team to simplify the creation and deployment of applications based on the Spring framework. It provides a fast, lightweight way to build stand-alone, executable

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains

In projects, some configuration information is often needed. This information may have different configurations in the test environment and the production environment, and may need to be modified later based on actual business conditions. We cannot hard-code these configurations in the code. It is best to write them in the configuration file. For example, you can write this information in the application.yml file. So, how to get or use this address in the code? There are 2 methods. Method 1: We can get the value corresponding to the key in the configuration file (application.yml) through the ${key} annotated with @Value. This method is suitable for situations where there are relatively few microservices. Method 2: In actual projects, When business is complicated, logic

1. Implementing SMS login based on session 1.1 SMS login flow chart 1.2 Implementing sending SMS verification code Front-end request description: Description of request method POST request path /user/code request parameter phone (phone number) return value No back-end interface implementation: @Slf4j@ ServicepublicclassUserServiceImplextendsServiceImplimplementsIUserService{@OverridepublicResultsendCode(Stringphone,HttpSessionsession){//1. Verify mobile phone number if
