spring boot redis 使用 2
寧國網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,寧國網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為寧國近1000家提供企業(yè)網(wǎng)站建設(shè)服務。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務好的寧國做網(wǎng)站的公司定做!
使用redis共享session
分布式系統(tǒng)中,Session 共享有很多的解決方案,其中托管到緩存中應該是最常用的方案之一
pom文件中引入依賴
<!-- redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- redis session -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
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數(shù)據(jù)庫索引(默認為0)
spring.redis.database=4
#連接池最大連接數(shù)(使用負值表示沒有限制)
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 權(quán)限認證自動裝配
不去掉會引起權(quán)限不足
----end----
標題名稱:springboot使用redissession
分享地址:http://chinadenli.net/article44/jecehe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司、響應式網(wǎng)站、定制開發(fā)、網(wǎng)站收錄、建站公司、網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)