成都网站建设设计

将想法与焦点和您一起共享

springboot使用redissession-创新互联

spring boot redis 使用 2

成都网站设计、成都网站制作过程中,需要针对客户的行业特点、产品特性、目标受众和市场情况进行定位分析,以确定网站的风格、色彩、版式、交互等方面的设计方向。成都创新互联公司还需要根据客户的需求进行功能模块的开发和设计,包括内容管理、前台展示、用户权限管理、数据统计和安全保护等功能。

使用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----

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


当前标题:springboot使用redissession-创新互联
网站地址:http://chengdu.cdxwcx.cn/article/dpssdo.html