當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringSession实现用户会话
生活随笔
收集整理的這篇文章主要介紹了
SpringSession实现用户会话
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<!-- 引入 redis 依賴 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- 引入spring安全框架 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency>
# session:
# store-type: redis
@EnableRedisHttpSession // 開啟使用redis作為spring session
@GetMapping("/setSession")
public Object setSession(HttpServletRequest request) {HttpSession session = request.getSession();session.setAttribute("userInfo", "new user");session.setMaxInactiveInterval(3600);session.getAttribute("userInfo");
// session.removeAttribute("userInfo");return "ok";
}
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public @interface SpringBootApplication {
/*** Exclude specific auto-configuration classes such that they will never be applied.* @return the classes to exclude*/
@AliasFor(annotation = EnableAutoConfiguration.class)
Class<?>[] exclude() default {};
?
總結
以上是生活随笔為你收集整理的SpringSession实现用户会话的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 实现Redis用户会话 - 2
- 下一篇: 分布式会话拦截器2 - 会话判断