File tree Expand file tree Collapse file tree 3 files changed +11
-32
lines changed
springboot-springdata-redis/src/main/java/com/jonssonyan Expand file tree Collapse file tree 3 files changed +11
-32
lines changed Original file line number Diff line number Diff line change 1
1
package com .jonssonyan .config ;
2
2
3
- import com .jonssonyan .service .RedisService ;
4
- import org .springframework .beans .factory .annotation .Autowired ;
5
- import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
6
- import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
7
3
import org .springframework .cache .CacheManager ;
8
4
import org .springframework .context .annotation .Bean ;
9
5
import org .springframework .context .annotation .Configuration ;
16
12
import org .springframework .data .redis .serializer .StringRedisSerializer ;
17
13
18
14
@ Configuration
19
- @ ConditionalOnClass (RedisService .class )
20
15
public class RedisConfig {
21
- private RedisTemplate <String , Object > redisTemplate ;
22
16
23
- @ Bean
24
- @ ConditionalOnMissingBean
25
- public RedisService redisService () {
26
- return new RedisService (redisTemplate );
27
- }
28
-
29
- @ Autowired
30
- public void setRedisTemplate (RedisTemplate <String , Object > redisTemplate ) {
31
- this .redisTemplate = redisTemplate ;
32
- }
33
-
34
- // redis configuration
35
- // -----------------------------------------------------------------------------------------------------------------
36
-
37
- /**
38
- * key 的序列化器
39
- */
17
+ // key 的序列化器
40
18
private final StringRedisSerializer keyRedisSerializer = new StringRedisSerializer ();
41
19
42
- /**
43
- * value 的序列化器
44
- */
20
+ // value 的序列化器
45
21
private final RedisFastJsonSerializer <Object > valueRedisSerializer = new RedisFastJsonSerializer <>(Object .class );
46
22
47
23
@ Bean
Original file line number Diff line number Diff line change 17
17
* @param <T>
18
18
*/
19
19
public class RedisFastJsonSerializer <T > implements RedisSerializer <T > {
20
+
20
21
// 新建的GenericFastJson2JsonRedisSerializer里面添加白名,防止fastjson 反序列化报错
21
22
static {
22
23
ParserConfig .getGlobalInstance ().addAccept ("com.jonssonyan" );
Original file line number Diff line number Diff line change 5
5
import org .apache .commons .collections4 .MapUtils ;
6
6
import org .apache .commons .io .FileUtils ;
7
7
import org .apache .commons .io .IOUtils ;
8
+ import org .springframework .beans .factory .annotation .Autowired ;
8
9
import org .springframework .data .redis .core .HashOperations ;
9
10
import org .springframework .data .redis .core .RedisTemplate ;
10
11
import org .springframework .stereotype .Service ;
13
14
import java .io .File ;
14
15
import java .io .FileOutputStream ;
15
16
import java .nio .charset .StandardCharsets ;
16
- import java .util .*;
17
+ import java .util .Base64 ;
18
+ import java .util .HashMap ;
19
+ import java .util .Map ;
20
+ import java .util .Objects ;
21
+ import java .util .Optional ;
17
22
import java .util .concurrent .TimeUnit ;
18
23
19
24
@ Service
20
25
public class RedisService {
21
26
22
- private final RedisTemplate <String , Object > redisTemplate ;
23
-
24
- public RedisService (RedisTemplate <String , Object > redisTemplate ) {
25
- this .redisTemplate = redisTemplate ;
26
- }
27
+ @ Autowired
28
+ private RedisTemplate <String , Object > redisTemplate ;
27
29
28
30
/**
29
31
* Description: 设值
You can’t perform that action at this time.
0 commit comments