btg-httpsession 分布式 session 实现开源项目

我要开发同款
匿名用户2019年12月31日
40阅读
开发技术Java
所属分类数据库相关
授权协议Apache

作品详情

btg-httpsession是实现了httpsession标准适用于普通web项目和jfinal项目的分布式session

使用方式一、配置方式:1、通过filter配置(非jfinal项目推荐配置方式);/****BTGHttpSessionRequest替换filter(localsession管理)*注意:此filter优先级必须大于业务系统处理相关filter**若需要redis、db模式的session管理:*1、请在初始化配置参数init-param*sessionDao:可选,默认为local。*local-使用local的BTGSessionDao;*redis-使用redis的BTGSessionDao*db-使用redis的BTGSessionDao;*dname:可选,默认为jfinal默认;*若sessionDao为redis,该参数则表示RedisPlugin的name;*若sessionDao为db,该参数表示ActiveRecordPlugin的name;*2、或者扩展此类,重写init方法完成sessionDao的初始化即可*/<filter><filter-name>btgsession</filter-name><filter-class>cn.usbtg.httpsession.servlet.filter.BTGHttpSessionFilter</filter-class><init-param><param-name>sessionDao</param-name><param-value>redis</param-value></init-param><init-param><param-name>dname</param-name><param-value>myredis</param-value></init-param></filter><filter-mapping><filter-name>btgsession</filter-name><url-pattern>/*</url-pattern></filter-mapping>2、(jfinal项目推荐)使用jfinal的plugin+interceptor(interceptor或handler,二选一)配置(若使用默认session管理容器无需配置plugin,仅当需要使用非默认BTGSessionDao实现时,需要在plugin中进行初始化);JfinalConfig:可选配置,用户初始化sessionDao实现方案publicvoidconfigPlugin(Pluginsme){//local(默认,无需配置)BTGSessionDaolocalSessionDao=newBTGLocalSessionDao();BTGSessionPluginsessionPlugin=newBTGSessionPlugin(localSessionDao);me.add(sessionPlugin);//redisBTGSessionDaoredisSessionDao=newBTGRedisSessionDao();BTGSessionDaoredisSessionDao=newBTGRedisSessionDao("myredis");BTGSessionPluginsessionPlugin=newBTGSessionPlugin(redisSessionDao);me.add(sessionPlugin);//dbBTGSessionDaodbSessionDao=newBTGDBSessionDao();BTGSessionDaodbSessionDao=newBTGDBSessionDao("mydb");BTGSessionPluginsessionPlugin=newBTGSessionPlugin(dbSessionDao);me.add(sessionPlugin);}Interceptor:必须配置,用于替换session管理机制me.add(newBTGHttpSessionInterceptor());Handler:必须配置,用于替换session管理机制me.add(newBTGHttpSessionHandler());二、调用API:1、使用BTGHttpSessionContext接口的实现类BTGStandardSessionContext直接完成对session的操作;getSession(StringsessionId):BTGStandardSessionContext.getSessionContext().getSession(sessionId)getNewSession():BTGStandardSessionContext.getSessionContext().getNewSession()更多api请查看BTGSessionContext接口2、(推荐)使用静态访问类SessionKit完成对session的操作;getSession(StringsessionId):SessionKit.getSession(sessionId)getNewSession():SessionKit.getNewSession()更多api请查看SessionKit类
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论