又双叒叕来session共享

之前写过两篇springboot分布式中的session共享解决方案,参考
《springboot中redis的使用和分布式session共享问题》《再谈session共享》
经过同事共同研究,原来springboot提供另外一种解决方案:0行代码解决方案

配置文件

spring.session.redis.namespace=自己定义的命名空间
spring.session.store-type=redis

是的,只需要这两行即可,不再需要其他配置或者代码实现,测试方法见上面两篇文章。

TIPS:1、使用redis解决session共享,那么就不能使用其他的session管理器,比如shiro自带的sessionManger,否则会导致以上配置失效
2、上面配置中没有提供超时配置,redis超时可以使用server.session.timeout=1800实现

附springboot提供另外的session管理机制

<pre class="programlisting" style="line-height: 1.4; color: black; font-size: 15px; padding: 6px 10px; background-color: rgb(248, 248, 248); border: 1px solid rgb(204, 204, 204); border-radius: 3px; clear: both; overflow: auto; font-family: Consolas, &quot;Liberation Mono&quot;, Courier, monospace; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"># SPRING SESSION ([SessionProperties](https://github.com/spring-projects/spring-boot/tree/v1.5.9.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionProperties.java))
spring.session.hazelcast.flush-mode=on-save # Sessions flush mode.
spring.session.hazelcast.map-name=spring:session:sessions # Name of the map used to store sessions.
spring.session.jdbc.initializer.enabled= # Create the required session tables on startup if necessary. Enabled automatically if the default table name is set or a custom schema is configured.
spring.session.jdbc.schema=classpath:org/springframework/session/jdbc/schema-@@platform@@.sql # Path to the SQL file to use to initialize the database schema.
spring.session.jdbc.table-name=SPRING_SESSION # Name of database table used to store sessions.
spring.session.mongo.collection-name=sessions # Collection name used to store sessions.
spring.session.redis.flush-mode=on-save # Sessions flush mode.
spring.session.redis.namespace= # Namespace for keys used to store sessions.
spring.session.store-type= # Session store type.</pre>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,314评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,040评论 6 342
  • 痞子“大牙”在“严打”中被请进公安局没几天就被放出来的事给他着实镀了一层金,使他的声望和威信短时间内就如钻天猴一样...
    暖曦阅读 4,225评论 9 17
  • “我信这山河大地,不信你誓语诚诚。”——扎西拉姆·多多 (一) 北京的深秋在我的记忆中,是伴随着一场“声势浩大”的...
    十七的臆想世界阅读 2,828评论 0 3
  • 赵霞1阅读 884评论 0 0