@Component public class TimeCostBeanPostProcessor implements BeanPostProcessor { MapcostMap = 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; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)