@Component public class TimeCostBeanPostProcessor implements BeanPostProcessor { Map<String, Long> costMap = Maps.newConcurrentMap(); @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { costMap.put(beanName, System.currentTimeMillis()); return bean; } @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { Long start = costMap.get(beanName); long cost = System.currentTimeMillis() - start; if (cost > 0) { costMap.put(beanName, cost); System.out.println("class: " + bean.getClass().getName() + "\tbean: "+ beanName + "\ttime: "+ cost); } return bean; } }
Spring监听bean加载时间
最新推荐文章于 2023-10-27 15:23:25 发布