Spring-Session具体的特性很是之多,具体的内容能够从文档中了解到,笔者作一点本身的总结,Spring Session的特性包括但不限于如下:java
一、引入依赖web
<dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> <version>2.0.2.RELEASE</version> </dependency> <dependency> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> <version>5.0.2.RELEASE</version> </dependency>
二、配置过滤器redis
在web.xml中配置过滤器,注意该过滤器必须在其余过滤器以前spring
<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> <dispatcher>REQUEST</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping>
三、配置redismongodb
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 1800) public class RedisHttpSessionConfig { @Bean public LettuceConnectionFactory connectionFactory() { RedisStandaloneConfiguration redisStandaloneConfiguration=new RedisStandaloneConfiguration(); //redis服务器主机ip redisStandaloneConfiguration.setHostName("127.0.0.1"); //使用第几个数据库 redisStandaloneConfiguration.setDatabase(0); //redis密码 redisStandaloneConfiguration.setPassword(RedisPassword.of("lgdsj2017")); //端口 redisStandaloneConfiguration.setPort(9379); return new LettuceConnectionFactory(redisStandaloneConfiguration); } }