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); } }