Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Jahson
jeecg-boot
提交
e2d9a66a
J
jeecg-boot
项目概览
Jahson
/
jeecg-boot
与 Fork 源项目一致
Fork自
jeecg / jeecg-boot
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jeecg-boot
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e2d9a66a
编写于
4月 22, 2019
作者:
JEECG低代码平台
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改redis配置,解决字典表无法使用问题
上级
8b1611ab
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
8 addition
and
73 deletion
+8
-73
jeecg-boot/src/main/java/org/jeecg/config/RedisConfig.java
jeecg-boot/src/main/java/org/jeecg/config/RedisConfig.java
+8
-73
未找到文件。
jeecg-boot/src/main/java/org/jeecg/config/RedisConfig.java
浏览文件 @
e2d9a66a
package
org.jeecg.config
;
import
java.lang.reflect.Method
;
import
java.time.Duration
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.annotation.Resource
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.annotation.CachingConfigurerSupport
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.cache.concurrent.ConcurrentMapCache
;
import
org.springframework.cache.interceptor.KeyGenerator
;
import
org.springframework.cache.support.SimpleCacheManager
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.cache.RedisCacheConfiguration
;
import
org.springframework.data.redis.cache.RedisCacheManager
;
import
org.springframework.data.redis.cache.RedisCacheWriter
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.RedisSerializationContext
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
...
...
@@ -46,7 +30,6 @@ public class RedisConfig extends CachingConfigurerSupport {
* 只需要讲注解上keyGenerator的值设置为keyGenerator即可</br>
* @return 自定义策略生成的key
*/
@Override
@Bean
public
KeyGenerator
keyGenerator
()
{
return
new
KeyGenerator
()
{
...
...
@@ -63,6 +46,14 @@ public class RedisConfig extends CachingConfigurerSupport {
};
}
// 这个注释不能放开,发现自定义缓存管理器,会导致实体解析失败
//TODO
// @Bean
// public CacheManager cacheManager() {
// RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(lettuceConnectionFactory);
// return builder.build();
// }
/**
* RedisTemplate配置
*/
...
...
@@ -85,61 +76,5 @@ public class RedisConfig extends CachingConfigurerSupport {
redisTemplate
.
afterPropertiesSet
();
return
redisTemplate
;
}
/**
* 此处的缓存到JAVA虚拟机内存,非存Redis
*/
@Override
@Bean
public
CacheManager
cacheManager
()
{
SimpleCacheManager
cacheManager
=
new
SimpleCacheManager
();
List
<
ConcurrentMapCache
>
list
=
new
ArrayList
<
ConcurrentMapCache
>();
list
.
add
(
new
ConcurrentMapCache
(
"dictCache"
));
list
.
add
(
new
ConcurrentMapCache
(
"jeecgDemo"
));
list
.
add
(
new
ConcurrentMapCache
(
"permission"
));
cacheManager
.
setCaches
(
list
);
cacheManager
.
afterPropertiesSet
();
return
cacheManager
;
}
/**
* Redis缓存支持设置缓存过期时间
* @param redisConnectionFactory
* @return
*/
@Bean
public
RedisCacheManager
redisCacheManager
(
RedisConnectionFactory
redisConnectionFactory
)
{
return
new
RedisCacheManager
(
RedisCacheWriter
.
nonLockingRedisCacheWriter
(
redisConnectionFactory
),
this
.
getRedisCacheConfigurationWithTtl
(
3600
),
//3600秒,默认策略,未配置的 key 会使用这个
this
.
getRedisCacheConfigurationMap
()
// 指定 key 策略
);
}
/**
* 指定redis缓存超时时间
* @return
*/
private
Map
<
String
,
RedisCacheConfiguration
>
getRedisCacheConfigurationMap
()
{
Map
<
String
,
RedisCacheConfiguration
>
redisCacheConfigurationMap
=
new
HashMap
<>();
redisCacheConfigurationMap
.
put
(
"dictTableCache"
,
this
.
getRedisCacheConfigurationWithTtl
(
600
));
// 600秒(表数据字典只缓存10分钟)
return
redisCacheConfigurationMap
;
}
private
RedisCacheConfiguration
getRedisCacheConfigurationWithTtl
(
Integer
seconds
)
{
Jackson2JsonRedisSerializer
<
Object
>
jackson2JsonRedisSerializer
=
new
Jackson2JsonRedisSerializer
<>(
Object
.
class
);
ObjectMapper
om
=
new
ObjectMapper
();
om
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
om
.
enableDefaultTyping
(
ObjectMapper
.
DefaultTyping
.
NON_FINAL
);
jackson2JsonRedisSerializer
.
setObjectMapper
(
om
);
RedisCacheConfiguration
redisCacheConfiguration
=
RedisCacheConfiguration
.
defaultCacheConfig
();
redisCacheConfiguration
=
redisCacheConfiguration
.
serializeValuesWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
jackson2JsonRedisSerializer
)
).
entryTtl
(
Duration
.
ofSeconds
(
seconds
));
return
redisCacheConfiguration
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录