首页 > 编程语言 > 详细

SpringMVC项目中启动自加载Listener

时间:2015-05-24 21:58:45      阅读:410      评论:0      收藏:0      [点我收藏+]

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));
		}
	}
}

SpringMVC项目中启动自加载Listener

原文:http://blog.csdn.net/tototuzuoquan/article/details/45954959

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!