网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

springboot使用redissession

spring boot redis 使用 2

宁国网站建设公司成都创新互联公司,宁国网站设计制作,有大型网站制作公司丰富经验。已为宁国近1000家提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的宁国做网站的公司定做!

使用redis共享session

分布式系统中,Session 共享有很多的解决方案,其中托管到缓存中应该是最常用的方案之一

  1. pom文件中引入依赖



    org.springframework.boot
    spring-boot-starter-data-redis



    org.springframework.boot
    spring-boot-starter-security



    org.springframework.session
    spring-session-data-redis

spring session 中默认加入了 security 不添加 security 依赖会抛异常:
java.lang.ClassNotFoundException: org.springframework.security.web.authentication.RememberMeServices

2.redis 配置

#redis配置
#Redis服务器地址
spring.redis.host=192.168.5.10
#Redis服务器连接端口
spring.redis.port=6379
#Redis数据库索引(默认为0)
spring.redis.database=4
#连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=50
#连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=3000
#连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=20
#连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=2
#连接超时时间(毫秒)
spring.redis.timeout=5000

spring.session.store-type=redis

3.在启动类中开启 redis session

@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
@MapperScan("com.example.demo.dao.mybatis")
@EnableCaching
@EnableRedisHttpSession
public class DemoApplication 

@SpringBootApplication(exclude = {SecurityAutoConfiguration.class}) 去掉 security 权限认证自动装配
不去掉会引起权限不足

----end----


本文题目:springboot使用redissession
新闻来源:http://bjjierui.cn/article/jecehe.html

其他资讯