Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
isc-core
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
isc-v3.1-tmp
isc-core
Commits
a0b698bb
Commit
a0b698bb
authored
Oct 23, 2024
by
hulei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
统一jacksonRedisTemplate
parent
92168b11
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
23 deletions
+3
-23
RedisTemplateConfig.java
...com/brilliance/isc/common/config/RedisTemplateConfig.java
+3
-23
No files found.
isc-common-service/src/main/java/com/brilliance/isc/common/config/RedisTemplateConfig.java
View file @
a0b698bb
package
com
.
brilliance
.
isc
.
common
.
config
;
package
com
.
brilliance
.
isc
.
common
.
config
;
import
com.brilliance.isc.support.redis.RedisTemplateBuilder
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.JsonTypeInfo
;
import
com.fasterxml.jackson.annotation.JsonTypeInfo
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
...
@@ -25,30 +26,8 @@ import java.util.List;
...
@@ -25,30 +26,8 @@ import java.util.List;
@Configuration
@Configuration
public
class
RedisTemplateConfig
{
public
class
RedisTemplateConfig
{
@Bean
(
"jacksonRedisTemplate"
)
@Bean
(
"jacksonRedisTemplate"
)
public
RedisTemplate
<
String
,
Object
>
jacksonRedisTemplate
(
RedisConnectionFactory
factory
)
{
public
RedisTemplate
<
String
,
Object
>
jacksonRedisTemplate
(
RedisConnectionFactory
factory
)
{
RedisTemplate
<
String
,
Object
>
template
=
new
RedisTemplate
<>();
return
RedisTemplateBuilder
.
craeteJacksonRedisTemplate
(
factory
);
template
.
setConnectionFactory
(
factory
);
ObjectMapper
objectMapper
=
new
ObjectMapper
();
objectMapper
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
objectMapper
.
activateDefaultTyping
(
LaissezFaireSubTypeValidator
.
instance
,
ObjectMapper
.
DefaultTyping
.
NON_FINAL
,
JsonTypeInfo
.
As
.
PROPERTY
);
// 使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
Jackson2JsonRedisSerializer
jacksonSeial
=
new
Jackson2JsonRedisSerializer
(
Object
.
class
);
jacksonSeial
.
setObjectMapper
(
objectMapper
);
// 值采用json序列化
template
.
setValueSerializer
(
jacksonSeial
);
//使用StringRedisSerializer来序列化和反序列化redis的key值
template
.
setKeySerializer
(
new
StringRedisSerializer
());
// 设置hash key 和value序列化模式
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashValueSerializer
(
jacksonSeial
);
template
.
afterPropertiesSet
();
return
template
;
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment