Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
spring-boot-starter-dsp
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
shenjiaqing
spring-boot-starter-dsp
Commits
d54c9376
Commit
d54c9376
authored
Aug 16, 2022
by
wangwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改warmup触发时机
parent
e9628ed1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
16 deletions
+12
-16
build.gradle
build.gradle
+1
-1
CacheConfig.java
...com/duiba/spring/boot/starter/dsp/warmup/CacheConfig.java
+11
-15
No files found.
build.gradle
View file @
d54c9376
...
@@ -38,7 +38,7 @@ allprojects {
...
@@ -38,7 +38,7 @@ allprojects {
}
}
group
=
"cn.com.duiba.boot"
group
=
"cn.com.duiba.boot"
version
=
"0.0.
57
"
version
=
"0.0.
35
"
}
}
subprojects
{
subprojects
{
...
...
spring-boot-starter-dsp-warmup/src/main/java/cn/com/duiba/spring/boot/starter/dsp/warmup/CacheConfig.java
View file @
d54c9376
package
cn
.
com
.
duiba
.
spring
.
boot
.
starter
.
dsp
.
warmup
;
package
cn
.
com
.
duiba
.
spring
.
boot
.
starter
.
dsp
.
warmup
;
import
cn.com.duiba.boot.event.MainContextRefreshedEvent
;
import
cn.com.duiba.boot.utils.AopTargetUtils
;
import
cn.com.duiba.boot.utils.AopTargetUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.JavaType
;
import
com.fasterxml.jackson.databind.JavaType
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
...
@@ -19,19 +17,19 @@ import org.apache.commons.lang3.StringUtils;
...
@@ -19,19 +17,19 @@ import org.apache.commons.lang3.StringUtils;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.aop.support.AopUtils
;
import
org.springframework.aop.support.AopUtils
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.AutoConfigureOrder
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.Type
;
import
java.lang.reflect.Type
;
import
java.util.*
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -41,8 +39,7 @@ import java.util.stream.Collectors;
...
@@ -41,8 +39,7 @@ import java.util.stream.Collectors;
* @Description
* @Description
*/
*/
@Configuration
@Configuration
@AutoConfigureOrder
(
Ordered
.
HIGHEST_PRECEDENCE
)
public
class
CacheConfig
implements
InitializingBean
{
public
class
CacheConfig
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CacheConfig
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CacheConfig
.
class
);
@Autowired
@Autowired
...
@@ -60,7 +57,6 @@ public class CacheConfig {
...
@@ -60,7 +57,6 @@ public class CacheConfig {
@Value
(
"${local.cache.warmup.enable:false}"
)
@Value
(
"${local.cache.warmup.enable:false}"
)
private
Boolean
cacheEnable
;
private
Boolean
cacheEnable
;
@EventListener
(
MainContextRefreshedEvent
.
class
)
public
void
onMainContextRefreshed
(){
public
void
onMainContextRefreshed
(){
String
[]
names
=
applicationContext
.
getBeanDefinitionNames
();
String
[]
names
=
applicationContext
.
getBeanDefinitionNames
();
for
(
String
beanName
:
names
)
{
for
(
String
beanName
:
names
)
{
...
@@ -129,8 +125,6 @@ public class CacheConfig {
...
@@ -129,8 +125,6 @@ public class CacheConfig {
}
}
// 顺序最靠后 等其他地方处理MainContextRefreshedEvent事件完成后
// 顺序最靠后 等其他地方处理MainContextRefreshedEvent事件完成后
@EventListener
(
MainContextRefreshedEvent
.
class
)
@Order
(
Ordered
.
LOWEST_PRECEDENCE
-
1
)
public
void
onServerCache
(){
public
void
onServerCache
(){
try
{
try
{
// 本地缓存预热开关 : 默认关闭
// 本地缓存预热开关 : 默认关闭
...
@@ -216,7 +210,6 @@ public class CacheConfig {
...
@@ -216,7 +210,6 @@ public class CacheConfig {
logger
.
info
(
"Caffeine Cache key = {} ; Caffeine Cache Size = {}"
,
k
,
asyncCache
.
synchronous
().
asMap
().
size
());
logger
.
info
(
"Caffeine Cache key = {} ; Caffeine Cache Size = {}"
,
k
,
asyncCache
.
synchronous
().
asMap
().
size
());
}
}
field
.
setAccessible
(
false
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
warn
(
"this bean : {} , no have method : {}, Lead to it cannot be deserialized , cause: {}"
,
split
[
0
],
field
.
getName
()
+
" Serialize"
,
e
);
logger
.
warn
(
"this bean : {} , no have method : {}, Lead to it cannot be deserialized , cause: {}"
,
split
[
0
],
field
.
getName
()
+
" Serialize"
,
e
);
}
}
...
@@ -230,6 +223,9 @@ public class CacheConfig {
...
@@ -230,6 +223,9 @@ public class CacheConfig {
}
}
@Override
public
void
afterPropertiesSet
()
{
onMainContextRefreshed
();
onServerCache
();
}
}
}
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