Commit d54c9376 authored by wangwei's avatar wangwei

修改warmup触发时机

parent e9628ed1
...@@ -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 {
......
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();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment