号称无缝整合httpsession 共享,

但注意如果存在第三方框架,例如SESSION并发控制,这个是需要自己重写session名单的.

关于redis session 共享 的session并发控制重写,请看我另一篇http://www.cnblogs.com/sweetchildomine/p/7007242.html

POM

    <!--redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>1.5.4.RELEASE</version>
</dependency>
<!-- redis session -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
RedisSessionConfig
/**
* Created by ZhenWeiLai on 2017/6/11.
*/
@Configuration
//maxInactiveIntervalInSeconds session超时时间,单位秒
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 600)
public class RedisSessionConfig {
}
RedisCacheConfig
package com.lzw.core.configuration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; /**
* Created by ZhenWeiLai on 2017/6/11.
*/
@Configuration
@EnableCaching
public class RedisCacheConfig extends CachingConfigurerSupport {
Logger logger = LoggerFactory.getLogger(RedisCacheConfig.class);
@Value("${spring.redis.host}")
private String host; @Value("${spring.redis.port}")
private int port; @Value("${spring.redis.timeout}")
private int timeout; @Value("${spring.redis.pool.max-idle}")
private int maxIdle; @Value("${spring.redis.pool.max-wait}")
private long maxWaitMillis; @Value("${spring.redis.password}")
private String password; @Bean
public JedisPool redisPoolFactory() {
logger.info("JedisPool注入成功!!");
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxIdle(maxIdle);
jedisPoolConfig.setMaxWaitMillis(maxWaitMillis); JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password); return jedisPool;
} @Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory cf) {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<String, String>();
redisTemplate.setConnectionFactory(cf);
return redisTemplate;
} @Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate); //默认超时时间,单位秒
cacheManager.setDefaultExpiration(3000);
//根据缓存名称设置超时时间,0为不超时
Map<String,Long> expires = new ConcurrentHashMap<>();
cacheManager.setExpires(expires); return cacheManager;
}
}

application.yml

spring:
datasource:
# readSize: 1
# name: writeDataSource
type: com.alibaba.druid.pool.DruidDataSource
write:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/cloud?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&useSSL=true
username: root
password: 123
initialSize: 10
maxActive: 100
maxWait: 60000
minIdle: 5
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20 #redis配置
redis:
host: 192.168.1.11
port: 6379
# REDIS (RedisProperties)
# Redis数据库索引(默认为0)
database: 0
# Redis服务器连接密码(默认为空)
password:
# 连接池最大连接数(使用负值表示没有限制)
# 连接超时时间(毫秒)
timeout: 0
pool:
max-active: 8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1
# 连接池中的最大空闲连接
max-idle: 8
# 连接池中的最小空闲连接
min-idle: 0

最新文章

  1. python基础-函数式编程
  2. 将数据导出成excel表
  3. 显示pdf
  4. IntelliJ IDEA创建web项目及异常问题解决
  5. c笔试题(1)
  6. 21 PagerTabStrip-PagerTitleStrip-viewPager
  7. Maven原型骨架及常见问题
  8. HTML5智能表单
  9. PHP反序列化漏洞学习
  10. C/C++遍历二维数组,列优先(column-major)比行优先(row-major)慢,why?
  11. 你真的了解String的常见API吗?
  12. Html设置html与body元素高度问题
  13. apache配置中ProxyPassReverse指令的含义
  14. ios 真机测试与发布详细流程,基于最新的开发者网站,ios7,xcode5(有截图的哦)[[[第一部分真机测试]]]
  15. java中需要用equals来判断两个字符串值是否相等
  16. DrawPrimitivesTest
  17. Unittest框架概念
  18. MySQL备份与恢复实战案例及生产方案
  19. python接口测试-项目实践(三)数据的处理示例
  20. 并查集——poj1611(入门)

热门文章

  1. Linux指令--文件和目录属性
  2. WebSphere--安全性
  3. android 中的ExpandableListView取消一级图标
  4. python并发编程之多进程(实现)
  5. 各模拟器adb连接端口
  6. 01_什么是数据结构以及C语言指针回顾
  7. c# 颜色RGB到HSB互相转换
  8. mysql导出数据至指定文件的命令
  9. 洛谷 [P1119] 灾后重建
  10. 洛谷 P3674 小清新人渣的本愿 [莫队 bitset]