﻿{"id":501,"date":"2019-07-23T20:58:52","date_gmt":"2019-07-23T12:58:52","guid":{"rendered":"http:\/\/blog.sway.com.cn\/?p=501"},"modified":"2019-07-23T20:58:52","modified_gmt":"2019-07-23T12:58:52","slug":"springboot%e5%88%a9%e7%94%a8redis%e5%af%b9session%e8%bf%9b%e8%a1%8c%e5%85%b1%e4%ba%ab","status":"publish","type":"post","link":"http:\/\/blog.sway.com.cn\/?p=501","title":{"rendered":"SpringBoot\u5229\u7528Redis\u5bf9session\u8fdb\u884c\u5171\u4eab"},"content":{"rendered":"<p>1\u3001\u5f15\u5165pom\u4f9d\u8d56\u5305<\/p>\n<p>&lt;dependency&gt;<br \/>\n&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;<br \/>\n&lt;artifactId&gt;spring-boot-starter-data-redis&lt;\/artifactId&gt;<br \/>\n&lt;\/dependency&gt;<br \/>\n&lt;dependency&gt;<br \/>\n&lt;groupId&gt;org.springframework.session&lt;\/groupId&gt;<br \/>\n&lt;artifactId&gt;spring-session-data-redis&lt;\/artifactId&gt;<br \/>\n&lt;\/dependency&gt;<\/p>\n<p>2\u3001\u914d\u7f6eapplication.application<\/p>\n<p>#\u00a0spring\u00a0session\u4f7f\u7528\u5b58\u50a8\u7c7b\u578b<br \/>\nspring.session.store-type=redis<\/p>\n<p>#\u914d\u7f6eredis\u96c6\u7fa4<\/p>\n<p>spring.redis.cluster.nodes=192.168.1.55:7000,192.168.1.53:7003<\/p>\n<p>3\u3001\u542f\u52a8\u7c7b\u4e2d\u589e\u52a0@EnableRedisHttpSession<\/p>\n<p>4\u3001\u4f7f\u7528<br \/>\nrequest.getSession().setAttribute(&#8220;username&#8221;,\u00a0&#8220;admin&#8221;);<br \/>\nString\u00a0userName\u00a0=\u00a0(String)\u00a0request.getSession().getAttribute(&#8220;username&#8221;);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u5f15\u5165pom\u4f9d\u8d56\u5305 &lt;dependency&gt; &lt;groupId&gt;org.spring [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[167],"tags":[172,173,168],"class_list":["post-501","post","type-post","status-publish","format-standard","hentry","category-springboot","tag-redis","tag-session","tag-springboot"],"_links":{"self":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=501"}],"version-history":[{"count":1,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/501\/revisions"}],"predecessor-version":[{"id":502,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/501\/revisions\/502"}],"wp:attachment":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=501"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}