springboot启动慢排查
1.排查每个bean加载时间是否有过长的
@Component
public class BeanInitCostTimeBeanPostProcessor implements BeanPostProcessor {
private static final Logger logger = LoggerFactory.getLogger(BeanInitCostTimeBeanPostProcessor.class);
private static final Map<String, Long> TIME_MAP = Maps.newConcurrentMap();
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
TIME_MAP.put(beanName, System.currentTimeMillis());
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (Objects.nonNull(TIME_MAP.get(beanName))) {
logger.info("beanName {}, init cost {}ms", beanName, System.currentTimeMillis() - TIME_MAP.get(beanName));
}
return bean;
}
}
原创:做时间的朋友