spring使用Redis存储Session 2015-10-29 编程 spring使用Redis存储Session准备spring web的maven项目 配置pom.xml添加依赖 12345678910111213141516<!-- pom.xml --><dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session</artifactId> <version>1.0.2.RELEASE</version></dependency><dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.4.1.RELEASE</version></dependency><dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.5.2</version></dependency> web.xml 添加过滤器 123456789<!-- web.xml --><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> spring 配置文件添加redis配置 12345678<context:annotation-config/><!-- 自动扫描必需 --><bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"/><bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <!-- redis 配置 --> <property name="hostName" value="localhost"/> <property name="port" value="6379"/></bean> 使用123456789101112@ResponseBody@RequestMapping("/get")public String index(Model model,HttpServletRequest request,String action,String msg,String key){ HttpSession session=request.getSession(); String message = "ok"; if ("set".equals(action)){ session.setAttribute(key, msg); }else if ("get".equals(action)){ message=(String)session.getAttribute(key); } return message;} 最后更新时间:2015-10-29 23:49:37 本文链接:http://ystyle.top/2015/10/29/springshi-yong-rediscun-chu-session/博客内容遵循 知识共享 署名 - 非商业性 - 相同方式共享 4.0协议 前一篇 Windows JDK 版本管理器 jvms 0.0.2 发布 下一篇 Docker 搭建redis 集群