- 浏览: 1571889 次
- 来自: 上海
文章分类
- 全部博客 (374)
- Java (101)
- Struts (54)
- Oracle (30)
- JavaScript (16)
- Spring (27)
- Hibernate (16)
- MyEclipse (3)
- JSF (1)
- FreeMarker (2)
- SiteMesh (2)
- JfreeChart (2)
- Ibatis (2)
- JSP (12)
- MyBatis (4)
- SWFupload (1)
- EJB (4)
- Jboss (4)
- WebService (2)
- Linux (16)
- Android (2)
- XML (6)
- Java 网络编程 (13)
- AXIS2 (1)
- FTP (1)
- Jswing (1)
- Socket (3)
- 杂文选集 (6)
- solr (2)
- PS (1)
- Tomcat (7)
- JDBC (9)
- Highcharts (1)
- maven (1)
- Nodejs (0)
- navicat (2)
- Exception (5)
- eclipse (3)
- jQuery (1)
- springMVC (4)
- MySQL (11)
- SVN (1)
- Sql Server (1)
- zookeeper (1)
- JVM (1)
- Groovy (2)
- Git (1)
- Nginx (1)
- DynamicReport (1)
- IDEA (2)
- JasperReports (1)
- Postgresql (2)
- Mac (1)
- gradle (1)
- 数据结构算法 (1)
最新评论
-
hpu145:
引用引用
java 千分位的添加和去除 -
被遗忘的下路:
少了个junit-4.8.2的包
SSH2整合完整案例(四十三) -
白天看黑夜:
java过滤emoji字符处理,希望能帮到你http://ww ...
emoji 表情图片解决方法 -
caipeiming:
这个挺好JavaScript实现input输入框控件只允许输入 ...
js 控制文本框只能输入中文、英文、数字等 -
双子树:
东西太好啦受教啊
Struts2 JSP中将list,set ,Map传递到Action然后<s:iterator>遍历(三十五)
spring-session 配置
依赖
web.xml 中配置
redis 配置 spring-session bean
遇到的问题
1:
web.xml 中配置 context-param 必须放在filter 前面
2 context-param 必须包含 redis spring-session bean 的配置
3 nginx 做轮询的时候 session 丢失了 造成 sessionid 每次都重新创建了
所以要配置 defaultCookieSerializer 这个bean
指定 domain 和 cookie path
关于这个问题 其实可以配置nginx 的时候 指定cook-path
http://blog.csdn.net/eonianglutton/article/details/54139586
http://www.cnblogs.com/zangdalei/p/6021352.html
依赖
gradle compile "redis.clients:jedis:2.9.0" //spring-session compile('org.springframework.data:spring-data-redis:1.8.3.RELEASE') compile('org.springframework.session:spring-session:1.2.2.RELEASE')
web.xml 中配置
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:spring-context.xml </param-value> </context-param> <!--spring-session--> <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>
redis 配置 spring-session bean
<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate"> <property name="retryPolicy"> <bean class="org.springframework.retry.policy.TimeoutRetryPolicy"> <property name="timeout" value="50"/> <!--50毫秒后重试--> </bean> </property> </bean> <!-- jedis 连接池配置 --> <bean id="jedisSessionPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxTotal" value="300"/> <property name="maxIdle" value="5"/> <property name="minIdle" value="1"/> <property name="maxWaitMillis" value="1000"></property> <property name="testOnBorrow" value="true"/> <!-- 调用return 一个对象方法时,是否检查其有效性 --> <property name="testOnReturn" value="true"/> </bean> <bean id="redisSentConfSystemServer" class="org.springframework.data.redis.connection.RedisSentinelConfiguration"> <property name="master"> <bean class="org.springframework.data.redis.connection.RedisNode"> <property name="name" value="${redis.sentinel.master.clound_data_server}"></property> </bean> </property> <property name="sentinels"> <set> <bean class="org.springframework.data.redis.connection.RedisNode"> <constructor-arg index="0" value="${redis.sentinel1.address.clound_data_server}"/> <constructor-arg index="1" value="${redis.sentinel1.port.clound_data_server}"/> </bean> <bean class="org.springframework.data.redis.connection.RedisNode"> <constructor-arg index="0" value="${redis.sentinel2.address.clound_data_server}"/> <constructor-arg index="1" value="${redis.sentinel2.port.clound_data_server}"/> </bean> <bean class="org.springframework.data.redis.connection.RedisNode"> <constructor-arg index="0" value="${redis.sentinel3.address.clound_data_server}"/> <constructor-arg index="1" value="${redis.sentinel3.port.clound_data_server}"/> </bean> </set> </property> </bean> <bean id="jedisConnFactSystemServer01" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <constructor-arg ref="redisSentConfSystemServer"/> <property name="usePool" value="true"/> <property name="timeout" value="10000"/> <property name="database" value="${redis.db.clound_data_server}"/> <property name="password" value="${redis.password.clound_data_server}"/> <property name="poolConfig" ref="jedisSessionPoolConfig"/> </bean> <bean id="redisSessionTemplate01" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="jedisConnFactSystemServer01"/> <property name="valueSerializer"> <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/> </property> </bean> <bean id="cacheUtil01" class="cn.mwee.utils.cache.RedisTemplateUtil"> <property name="stringRedisTemplate" ref="redisSessionTemplate01"/> <property name="retryTemplate" ref="retryTemplate"/> </bean> <!--redis config-end--> <!--spring-session--> <bean id="redisHttpSessionConfiguration" class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"> <property name="maxInactiveIntervalInSeconds" value="1800" /> <property name="cookieSerializer" ref="defaultCookieSerializer"/> </bean> <bean id="defaultCookieSerializer" class="org.springframework.session.web.http.DefaultCookieSerializer"> <property name="domainName" value="${wpos.report.domainName}"/> <!--<property name="cookieName" value="JSESSIONID"/>--> <property name="cookiePath" value="${wpos.report.cookiePath}"></property> <!-- <property name="domainNamePattern" value="^.+?\.(\w+\.[a-z]+)$"></property>--> </bean>
遇到的问题
1:
web.xml 中配置 context-param 必须放在filter 前面
2 context-param 必须包含 redis spring-session bean 的配置
3 nginx 做轮询的时候 session 丢失了 造成 sessionid 每次都重新创建了
所以要配置 defaultCookieSerializer 这个bean
指定 domain 和 cookie path
关于这个问题 其实可以配置nginx 的时候 指定cook-path
解决nginx使用proxy_pass反向代理时,session丢失的问题 这2天在测试Nginx作为反向代理到Tomcat应用时,session丢失的问题。经过一系列查看官方文档和测试,发现如下: 1、如果只是host、端口转换,则session不会丢失。例如: location /testwx { proxy_pass http://127.0.0.1:8080/testwx; } 通过浏览器访问http://127.0.0.1/testwx时,浏览器的cookie内有jsessionid。再次访问时,浏览器会发送当前的cookie。 2、如果路径也变化了,则需要设置cookie的路径转换,nginx.conf的配置如下 location /testwx { proxy_pass http://127.0.0.1:8080/wx; } 通过浏览器访问http://127.0.0.1/testwx时,浏览器的cookie内没有jsessionid。再次访问时,后台当然无法获取到cookie了。 详细看了文档:http://nginx.org/en/docs/http/ngx_http_proxy_module.html?&_ga=1.161910972.1696054694.1422417685#proxy_cookie_path 加上路径转换:proxy_cookie_path /wx /testwx;则可以将wx的cookie输出到testwx上,Tomcat的session正常了。正确的配置是: location /testwx { proxy_pass http://127.0.0.1:8080/wx; proxy_cookie_path /wx /testwx;#这里的路径要注意对应关系 }
http://blog.csdn.net/eonianglutton/article/details/54139586
http://www.cnblogs.com/zangdalei/p/6021352.html
发表评论
-
Spring AspectJ Aop Annotation
2017-03-29 17:08 662import org.aspectj.lang.Proce ... -
spring 第13天 使用@scheduled注解执行定时任务
2015-01-06 23:11 54014我们使用spring的注解 @Scheduled 执行定时任务 ... -
Spring 第12天,事务传播属性和 隔离级别
2014-09-28 00:36 7711 事务的传播属性(Propagation) 1) REQ ... -
spring 第11天 quartz任务调度
2014-08-24 13:59 1098Quartz是一个强大的企业级任务调度框架,Spring中继承 ... -
spring 第10 天 AOP 面向切面
2014-08-21 00:08 1716AOP(Aspect Orient Programming ... -
spring 第9天 Resurce 资源访问
2014-08-17 22:20 1823Spring Resource接口 spring提供的Reso ... -
spring 第8天 Spring 注解
2014-08-17 15:33 1432spring注解 @Component:标注一个普通的sp ... -
spring 第7天 Bean,BeanFactory处理器,配置器
2014-08-16 21:46 1183spring 两种后处理器 第一种,Bean 后处理器 对容器 ... -
spring 第6天SpEL,P命名空间,Util Schema
2014-08-13 22:52 1263使用p名称空间配置属性 ... -
spring 第5天不同作用域的bean,注入Field,方法返回值
2014-08-11 22:31 2060协调作用域不同步的bean 问题是;当一个singleton的 ... -
spring 第4天bean继承,init,destory-method
2014-08-10 17:54 1598深入理解Spring容器中的b ... -
spring 第3天使用java类和XML配置bean
2014-08-09 16:51 1458下面采用java类来配置bean,前面都采用xml进行配置be ... -
spring 第2天,bean作用域,自动注入集合
2014-08-06 22:16 1882sping容器中的Bean <!---beans的全 ... -
spring 第1天 IOC,DI,国际化,容器事件
2014-08-04 21:27 13561.构造注入(就是使用 构 ... -
SpringMVC 注解 和非注解
2014-01-26 10:29 17973首先看看非注解的项目结构 在web.xml文件 配置spr ... -
详解spring 每个jar的作用
2013-11-19 23:54 3868spring.jar 是包含有完整 ... -
Spring配置Hibernate事务
2013-11-10 13:45 1175为了保证数据的一致性,在编程的时候往往需要引入事务这个概念。事 ... -
Spring 中引用Properties文件
2013-08-29 14:39 10607其中部分配置信息(邮件发送相关): #邮件发送的相关配置 ... -
Spring IOC控制反转 依赖注入DI
2012-12-15 09:37 2293目录 1.使用IOC控制反转 中的DI依赖注入 手工注入 ... -
Spring IOC控制反转 依赖注入DI
2012-12-14 16:23 8目录 1.使用IOC控制反转 中的DI依赖注入 (两种配置方式 ...
相关推荐
赠送jar包:spring-session-data-redis-2.0.4.RELEASE.jar; 赠送原API文档:spring-session-data-redis-2.0.4.RELEASE-javadoc.jar; 赠送源代码:spring-session-data-redis-2.0.4.RELEASE-sources.jar; 赠送...
赠送jar包:spring-session-data-redis-2.0.4.RELEASE.jar; 赠送原API文档:spring-session-data-redis-2.0.4.RELEASE-javadoc.jar; 赠送源代码:spring-session-data-redis-2.0.4.RELEASE-sources.jar; 赠送...
赠送jar包:spring-session-core-2.0.5.RELEASE.jar; 赠送原API文档:spring-session-core-2.0.5.RELEASE-javadoc.jar; 赠送源代码:spring-session-core-2.0.5.RELEASE-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:spring-session-1.3.5.RELEASE.jar; 赠送原API文档:spring-session-1.3.5.RELEASE-javadoc.jar; 赠送源代码:spring-session-1.3.5.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-session-...
spring-session+spring依赖jar包,包含spring4.0.2.RELEASE相关jar包和commons-pool2-2.4.2.jar,jedis-2.7.3.jar,spring-data-redis-1.6.2.RELEASE.jar,spring-session-1.1.1.RELEASE.jar
赠送jar包:spring-session-1.3.5.RELEASE.jar; 赠送原API文档:spring-session-1.3.5.RELEASE-javadoc.jar; 赠送源代码:spring-session-1.3.5.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-session-...
commons-pool2-2.3.jar,jedis-2.8.0.jar,spring-data-redis-1.6.0.RELEASE.jar,spring-session-1.1.1.RELEASE.jar,Spring-data-redis(Version 1.6.0.RC1)中文版.pdf
赠送jar包:spring-session-1.3.0.RELEASE.jar; 赠送原API文档:spring-session-1.3.0.RELEASE-javadoc.jar; 赠送源代码:spring-session-1.3.0.RELEASE-sources.jar; 包含翻译后的API文档:spring-session-...
自己实现spring-session,实现单点登陆的功能 使用filter拦截用户的请求,在filter中包装request,在request的包装类requestWrapper中,重写getSession(), 和getSession(boolean create)。自己实现httpSession,...
spring-session-1.2.1 源码spring-session-1.2.1 源码spring-session-1.2.1 源码
赠送jar包:spring-session-core-2.0.5.RELEASE.jar; 赠送原API文档:spring-session-core-2.0.5.RELEASE-javadoc.jar; 赠送源代码:spring-session-core-2.0.5.RELEASE-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:spring-session-1.3.0.RELEASE.jar 赠送原API文档:spring-session-1.3.0.RELEASE-javadoc.jar 赠送源代码:spring-session-1.3.0.RELEASE-sources.jar 包含翻译后的API文档:spring-session-1.3.0....
spring5+hibernate5+Spring-session-data-redis2+Spring-data-redis2整合
包含spring4.0相关jar包和commons-pool2-2.4.2.jar,jedis-2.7.3.jar,spring-data-redis-1.6.2.RELEASE.jar,spring-session-1.1.1.RELEASE.jar
spring-session-1.3.1.RELEASE.zip
spring-session的官方文档pdf版本,下载到本地比较方便。描述了如何结合redis、jdbc等多种中间件来实现session共享。其中有代码示例和github项目示例的链接。
spring-session+spring++redis的依赖包,jedis-2.7.3,spring-data-redi,spring-session-1+commons-pool2
通过spring-session 和redis 达到跨域同应用时 session 统一存储。在应用中实现单点登录操作
session共享例子工程使用spring-session
spring-aop-1.1.1.jar spring-aop-1.2.6.jar spring-aop-1.2.9.jar spring-aop-2.0.2.jar spring-aop-2.0.6.jar spring-aop-2.0.7.jar spring-aop-2.0.8.jar spring-aop-2.0.jar spring-aop-2.5.1.jar spring-aop-...