springsession使用redis
生活随笔
收集整理的這篇文章主要介紹了
springsession使用redis
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先通過maven或gradle加載相關依賴
<!--spring session--> <dependency><groupId>org.springframework.session</groupId><artifactId>spring-session</artifactId><version>1.3.0.RELEASE</version> </dependency> <dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-redis</artifactId><version>1.7.6.RELEASE</version> </dependency> <dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>2.9.0</version> </dependency>配置servlet容器
<!--spring session--> <!--必須是第一個--> <filter><filter-name>springSessionRepositoryFilter</filter-name><filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping><filter-name>springSessionRepositoryFilter</filter-name><url-pattern>/*</url-pattern> </filter-mapping> springsession本質上是通過filter來處理session的
配置spring
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> </bean> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"><property name="hostName" value="127.0.0.1" /><property name="port" value="6379" /><property name="password" value="" /><property name="timeout" value="1800" /><property name="poolConfig" ref="jedisPoolConfig" /><property name="usePool" value="true" /> </bean> <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"><property name="connectionFactory" ref="jedisConnectionFactory" /> </bean> <bean id="redisHttpSessionConfiguration" class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"><property name="maxInactiveIntervalInSeconds" value="30" /> </bean>訪問瀏覽器
看到JSESSIONID變成了SESSION
在redis查看key,可以看到相關數據。
總結
以上是生活随笔為你收集整理的springsession使用redis的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QT使用winsocket
- 下一篇: 安装CocoaPod