spring session,集群环境下的session共享解决方案
来源:互联网 发布:大学生兼职平台知乎 编辑:程序博客网 时间:2024/05/19 02:04
之前在集群环境下需要解决session共享的问题,更多的时候我们是使用servlet容器例如tomcat提供的集群配置来解决session的复制问题。今天介绍一种简单的解决方案。
http://docs.spring.io/spring-session/docs/current/reference/html5/guides/httpsession.html#updating-dependencies
这里有关spring session的详细介绍,其使用起来也相当简单。
1:在pom文件中引入spring session的相关依赖
<dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> <version>1.1.1.RELEASE</version> <type>pom</type> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.2.5.RELEASE</version> </dependency></dependencies>
2 由于官网给出的是一种java代码配置的方式,在项目中,我们更多的是使用配置的方式来进行spring session的配置。因而我们需要搜索相关资料进行配置。
1:在web.xml的配置文件中加载spring-session的配置文件,比如spring-session.xml。
<filter> <filter-name>springSessionRepositoryFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSessionRepositoryFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
注意事项:这个filter的配置应该在web工程的其他filter配置之前。
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:spring-session.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
加载该配置文件,可以和其他配置文件一起加载,以逗号隔开即可。例如:
<param-value>classpath:spring-servlet.xml,classpath:customer.xml</param-value>
2:在spring-session.xml的配置文件中配置相关的信息。
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config/> <!--springSession 配置--> <bean id="sessionConfiguration" class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"> <!--修改session的有效时间--> <property name="maxInactiveIntervalInSeconds" value="1800"></property> </bean> <bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <property name="hostName" value="xxx.xx.xxx.xx"></property> <property name="port" value="6379"></property> </bean></beans>
注意事项:如上的配置需要开启对应的redis服务。有关redis的学习,网上教材很多,在这里不加赘述。
个人理解:由于spring-session 只是将原生的session以指定的方式进行存储,至于session的操作,它没有什么修改,无侵入,装饰者模式。
0 0
- spring session,集群环境下的session共享解决方案
- 分布式集群环境下Session共享的简单解决方案
- 集群环境下spring+session+redis,session共享问题
- spring session解决集群环境下session共享问题
- 集群下session共享问题的解决方案.
- 集群下的session共享
- spring Session + Redis集群 + 哨兵部署下实现Session共享
- 分布式集群系统下的高可用session解决方案—Session共享
- 集群中的session共享解决方案
- spring-session实现分布式集群session的共享
- spring-session实现分布式集群session的共享
- spring-session+redis集群实现Session共享
- Apache shiro集群实现 (六)分布式集群系统下的高可用session解决方案---Session共享
- Apache shiro集群实现 (六)分布式集群系统下的高可用session解决方案---Session共享
- Apache shiro集群实现 (六)分布式集群系统下的高可用session解决方案---Session共享
- Apache shiro集群实现 (六)分布式集群系统下的高可用session解决方案---Session共享
- Session共享的解决方案
- Session共享的解决方案
- 001 java 线程基础
- java多线程循环打印A,B,C
- std::string源码探秘和性能分析
- Java多线程编程3--线程间通信实例--等待/通知之交叉备份
- Cortex-M3 堆栈操作
- spring session,集群环境下的session共享解决方案
- linux 命令学习之 sort
- 全局变量$_SERVER
- Yarn源码分析之MapReduce作业中任务Task调度整体流程(一)
- DatabaseMetaData元数据
- LeetCode-6.ZigZag Conversion
- CUDA reference
- ACM第三次练习—1005
- 初探jquery之强大丰富的选择器