Based on springboot, integrate redis, and use redis to realize distributed sessio sharing
- Introduce redis dependency
- Introduce data-redis dependency
<!--redis依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<!--data-redis依赖-->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
- Add the annotation
@EnableRedisHttpSession to the startup class
Then follow the previous operations to save and retrieve the session. For
example:
session.getAttributr("key")
session.setArrtibute("key",value)
//session移除:
@RequestMapping("logout")
public void logout(HttpServletRequest request){
//退出登录
request.getSession().invalidate();//失效
}