# session-manager
**Repository Path**: china_qd/session-manager
## Basic Information
- **Project Name**: session-manager
- **Description**: 统一session管理-redis,在spring3时因为没有spring-session,也不想直接用tomcat的session,可以用这个。
fork from: https://github.com/blackshadowwalker/session-manager
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 2
- **Created**: 2016-05-27
- **Last Updated**: 2020-12-18
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
#session-manager
keywords: session manager; redis session manager; redis session;
# 1. config listener
set JedisPool and cacheEngine, new customer CacheListener extends CacheEngineLoadListener:
CacheEngineLoadListener.java
````java
public class CacheListener extends CacheEngineLoadListener {
private static Log log = LogFactory.getLog(CacheListener.class);
protected WebApplicationContext ctx;
@Override
public void contextInitialized(ServletContextEvent event) {
ServletContext servletContext = event.getServletContext();
this.ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);//get spring ctx
JedisPool jedisPool = this.ctx.getBean(JedisPool.class);//get jedisPool with spring
log.info(jedisPool);
servletContext.setAttribute(RedisCacheEngine.JEDIS_POOL, jedisPool);
super.contextInitialized(event);
}
@Override
public void contextDestroyed(ServletContextEvent event) {
super.contextDestroyed(event);
}
}
````
# 2. config web.xml (CacheListener & CacheSessionFilter)
|Parameter|Required|type|Default value|description|
|----|----|----|----|----|
|maxInactiveInterval | false | int | 28800 | session expired time in second |
|cookieDomain | false | string | sub domain| set cookie domain |
|tldEnable | false | boolean| false | set cookie use top level domain |
|cookieSessionIdName | false | string | SESSIONID | session id name in cookie |
|cookieContextPath | false | string | / | cookie context path |
|sessionCacheKeyPrefix | false | string | session | session key prefix in redis |
|sessionAttributeListeners | false | string | null | javax.servlet.http.HttpSessionListeners name, split with comma|
config web.xml
````xml
com.ezhe.www.listener.CacheListener
CacheSessionFilter
com.gozap.session.servlet.filter.session.CacheSessionFilter
session expired time in second
maxInactiveInterval
3600
session prefix int redis
sessionCacheKeyPrefix
session-ezhe
use top level domain for sessionId
tldEnable
true
CacheSessionFilter
/*
.... other filters
````
session-manager.png
