---
title: "现有web系统替换成Spring Boot2框架 之9 session 共享"
author: "sanry"
date: "2019-02-22T11:24:37Z"
tags: []
categories: ["编程语言"]
slug: "web-spring-boot2-9-session"
draft: false
lastmod: "2019-02-22T11:24:37Z"
id: 2437836
url: "https://sanry.iteye.com/blog/2437836"
---

## **9.1 在pom.xml中配置依赖包**

&lt;!--spring boot 与redis应用基本环境配置 --&gt;

&lt;dependency&gt;

    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;

    &lt;artifactId&gt;spring-boot-starter-data-redis&lt;/artifactId&gt;

&lt;/dependency&gt;

&lt;!--spring session 与redis应用基本环境配置,需要开启redis后才可以使用，不然启动Spring boot会报错 --&gt;

&lt;dependency&gt;

    &lt;groupId&gt;org.springframework.session&lt;/groupId&gt;

    &lt;artifactId&gt;spring-session-data-redis&lt;/artifactId&gt;

&lt;/dependency&gt;

&lt;!--jedis --&gt;

&lt;dependency&gt;

    &lt;groupId&gt;redis.clients&lt;/groupId&gt;

    &lt;artifactId&gt;jedis&lt;/artifactId&gt;

    &lt;version&gt;2.9.0&lt;/version&gt;

&lt;/dependency&gt;

 

## **9.2 在application.properties中添加配置**

\# REDIS (RedisProperties)

\# Redis服务器地址

spring.redis.host=localhost

\# Redis服务器连接端口

spring.redis.port=6379

\# Redis服务器连接密码（默认为空）

spring.redis.password=

\# 连接池最大连接数（使用负值表示没有限制）

spring.redis.jedis.pool.max-active=20

\# 连接池最大阻塞等待时间（使用负值表示没有限制）

spring.redis.jedis.pool.max-wait=-1

\# 连接池中的最大空闲连接

spring.redis.jedis.pool.max-idle=15

\# 连接池中的最小空闲连接

spring.redis.jedis.pool.min-idle=0

\# 连接超时时间（毫秒）

spring.redis.timeout=1000