码迷,mamicode.com
首页 > 编程语言 > 详细

SpringMVC项目中启动自加载Listener

时间:2015-05-24 22:00:15      阅读:323      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!