<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # spring boot + redis 目前是主要流行的配置 通過spring boot + redis實現session共享的步驟如下: ## 運行redis注意 如果是windows運行redis,需要自定義一個bat文件,最重要的時候conf文件要配置上,bat文件內容: `redis-server redis.windows.conf` ## 添加依賴 pom.xml增加以下依賴: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-redis</artifactId> </dependency> <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> </dependency> ``` 注意,在有的IDEA版本中的m`aven projects `面板中,會提示 `spring-boot-starter-redis` 未找到,所以這里可以改成` spring-boot-starter-data-redis`,拒查兩個類內容是一樣的。 ## 添加配置類 在項目目錄里隨便找個位置,新建一個配置類,內容如下。 ~~~ @Configuration @EnableRedisHttpSession public class RedisSessionConfig { } ~~~ @EnableRedisHttpSession這個注解是由spring-session-data-redis提供的。 ## 配置redis 首先電腦里得有redis,否則無法使用,windows安裝redis也很簡單,請自行百度。 application.properties里設置主機和端口: ~~~ spring.redis.host=localhost spring.redis.port=6379 ~~~ 另外還有很多其他配置: ~~~ spring.redis.host=localhost spring.redis.port=6379 spring.redis.database=0 spring.redis.password= spring.redis.timeout=300 spring.redis.maxIdle=8 spring.redis.minIdle=0 spring.redis.maxActive=8 spring.redis.maxWait=-1 ~~~ 如果redis配置錯誤,會提示無法連接Jedis提示。注意默認端口是6379,網上有的寫錯了寫成6397了,不要直接復制。 ## 萬事具備,來一個controller搞一下 ~~~ @ResponseBody @RequestMapping(value = "/setsession", method = RequestMethod.GET) public Map<String, Object> setSession (HttpServletRequest request){ Map<String, Object> map = new HashMap<>(); request.getSession().setAttribute("設置session的網址是", request.getRequestURL()); // 設置session值 map.put("request Url", request.getRequestURL()); return map; } @ResponseBody @RequestMapping(value = "/getsession", method = RequestMethod.GET) public Object getSettion (HttpServletRequest request){ Map<String, Object> map = new HashMap<>(); map.put("sessionId", request.getSession().getId()); // 取值 map.put("message", request.getSession().getAttribute("map")); return map; } ~~~ @ResponseBody 可以看情況加,它返回的是json類型字符串;如果類里注解了@RestController就省略掉。 ## 訪問一下 http:://127.0.0.1/setsession,瀏覽器輸出: ``` {"設置session的網址是":"http://localhost:8080/setsession"} ``` http:://127.0.0.1/getsession,瀏覽器輸出: ``` {"sessionId":"...","message":"http://localhost:8080/setsession"} ``` 支持多端口共享。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看