pom依赖(快照版):

          <dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>
<version>5.0.0.Beta1</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>

 pom.xml正式版:

		<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>
<version>4.2.2.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

  

 RedisSession.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.context.annotation.Bean;

//依赖包不要导入错。
@EnableRedisHttpSession
@EnableConfigurationProperties(RedisProperties.class)
public class RedisConfiguration { @Resource
private RedisProperties redisProperties; @Bean
public LettuceConnectionFactory connectionFactory() {
LettuceConnectionFactory factory = new LettuceConnectionFactory();
factory.setHostName("localhost");
factory.setPassword("redispassword");
factory.setDatabase(0);
factory.setTimeout(5000);
factory.setPort(6379);
return factory;
} }

  然后在把值放入到HttpSession里面就会被自动放入到redis里面了。在集群下自动达到共享session的功能。

如:

  public ResponseEntity<Object> browseCunAction(@RequestParam("key")String key,@RequestParam("value")String value,HttpSession session) throws Exception {
session.setAttribute(key, value);
return ResponseEntity.ok(Collections.singletonMap(key, value));
}

  

最新文章

  1. CSS兼容各浏览器的hack
  2. swift 判断字符串长度
  3. [XAF] How to improve the application&#39;s performance
  4. 【转】 linux下的g++编译器安装
  5. mysql 字符串处理优化
  6. [转]Responsive Tables Demo
  7. [SAP ABAP开发技术总结]BAPI调用
  8. C/C++ 框架,类库,资源集合
  9. 微信web开发者工具调试
  10. nginx——rewrite模块
  11. Windows命令行(DOS命令)教程-8 (转载)http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_7.html
  12. ubuntu14.04 64位 安装eclipse出错
  13. 201621123060《JAVA程序设计》第八周学习总结
  14. numpy.squeeze()是干啥的
  15. maven将依赖的jar包复制到指定位置
  16. 解决ASP.NET中ServiceStack.Redis每小时6000次访问请求的问题
  17. struts2_E_commerce_maven
  18. PyQt5 各种菜单实现
  19. Oracle 11g 分区拆分与合并
  20. Java导包后在测试类中执行正确但在Servlet中执行错误报ClassNotFoundException或者ClassDefNotFoundException解决办法

热门文章

  1. spring java 方式配置JedisPool Bean
  2. Mapper not initialized. Call Initialize with appropriate configuration.
  3. [Functional Programming ADT] Initialize Redux Application State Using The State ADT
  4. 云计算之路-试用Azure:竟然无法重置虚拟机的管理员密码
  5. Adobe Acrobat Pro 11安装激活
  6. iOS程序发布测试-生成ad hoc证书
  7. SuperMap iClient如何使用WMS地图服务
  8. json servlet通信 显示数据
  9. Name与x:Name的关系
  10. 在windows 2012中安装sharepoint 2013时遇到问题的处理办法