In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will take you to understand how to set the expiration time of session in springboot project. The knowledge points in this article are very detailed. Friends who feel helpful can browse the content of the article together with the editor, hoping to help more friends who want to solve this problem to find the answer to the problem. Let's follow the editor to learn more about "how to set the expiration time of session in springboot projects".
Here we only introduce the session time setting of springboot2.0.
Duration converts string mode, default is positive, negative starts with -, followed by P, (letters are not case sensitive) D: day T: the separator between day and hour H: hour M: minute S: second each unit must be a number, and the order of minutes and seconds must not be out of order.
For example, PT10M is set to 10 minutes.
The following method is set for 24 hours.
The wrong setting is in the following way, which does not work.
Server.servlet.session.timeout=30s or use the second method session1.setMaxInactiveInterval (60 / 60); / / set session to expire in an hour, springboot set session to fail, if it is version 1.5.6
Here you can add the bean file to the application
Package com.example.demo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;import org.springframework.context.annotation.Bean;@SpringBootApplicationpublic class DemoApplication {undefinedpublic static void main (String [] args) {SpringApplication.run (DemoApplication.class, args) } / / set session expiration time @ Beanpublic EmbeddedServletContainerCustomizer containerCustomizer () {return new EmbeddedServletContainerCustomizer () {public void customize (ConfigurableEmbeddedServletContainer container) {container.setSessionTimeout (7200); / / in S}};}}
The second one.
You can also set the
Application.yml
Server:port: 8081servlet:session:timeout: 60s
The third @ RestControllerpublic class HelloController {undefined@PostMapping ("test") public Integer getTest (@ RequestParam ("nyy") String nn, HttpServletRequest httpServletRequest) {HttpSession session = httpServletRequest.getSession (); session.setMaxInactiveInterval (60); int maxInactiveInterval = session.getMaxInactiveInterval (); long lastAccessedTime = session.getLastAccessedTime (); return maxInactiveInterval;}}
What is springboot? springboot is a new programming specification, which is designed to simplify the initial construction and development process of new Spring applications. SpringBoot is also a framework that serves the framework, and the scope of services is to simplify configuration files.
Thank you for your reading, the above is the whole content of "how to set the expiration time of session in springboot project". Friends who learn to learn to do it quickly. I believe that the editor will certainly bring you better quality articles. Thank you for your support to the website!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.