SpringMVC项目中启动自加载Listener
package com.kuman.cartoon.listener; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.stereotype.Service; import com.kuman.cartoon.entity.pointrate.PointRate; import com.kuman.cartoon.service.pointrate.IPointRateService; import com.kuman.cartoon.utils.PointRateUtil; /** * 这个监听器用于启动的时候将积分等级信息取出,让后保存在Map集合中。 * @author to.to */ @Service public class PointRateListener implements ApplicationListener<ContextRefreshedEvent> { //private static final Logger LOGGER = Logger.getLogger(PointRateListener.class); @Autowired IPointRateService pointRateService; /** * 启动加载执行 */ @Override public void onApplicationEvent(ContextRefreshedEvent event) { List<PointRate> pointRates = pointRateService.findAll(); for (int i = 0; i < pointRates.size(); i++) { PointRateUtil.pointRateMap.put(i, pointRates.get(i)); //LOGGER.info("PointRateUtil.pointRateMap " + i + " = " + pointRates.get(i)); } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。