package com.cn.rzx.listener;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletContext;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;

import com.cn.rzx.system.pojo.Right;

/**
 * 初始化权限监听器,在spring初始化完成后立即调用.
 */
@Component
@SuppressWarnings("rawtypes")
public class IniRightListener implements ApplicationListener,
		ServletContextAware {
	@Resource
//	private RightService rs;

	// 接受ServletContext
	private ServletContext sc;

	public void onApplicationEvent(ApplicationEvent arg0) {
		// 上下文刷新事件
		if (arg0 instanceof ContextRefreshedEvent) {
			// 查出所有权限
			List<Right> rights = null;//rs.findAllEntities();
			Map<String, Right> map = new HashMap<String, Right>();
			for (Right r : rights) {
				map.put(r.getRightUrl(), r);
			}
			if (sc != null) {
				sc.setAttribute("all_rights_map", map);
				System.out.println("初始化所有权限到Application中!!!!");
			}
		}
	}

	// 注入ServletContext
	public void setServletContext(ServletContext servletContext) {
		this.sc = servletContext;
	}
}
最近下载更多
1057148049  LV11 2021年12月6日
543666826  LV33 2021年11月18日
15281682932  LV9 2021年6月21日
xyy999  LV1 2021年5月26日
混的人6666  LV2 2020年8月1日
kkkxyh  LV13 2020年5月4日
18337281853  LV12 2020年4月29日
晓白1234  LV3 2020年4月27日
775794341  LV13 2020年4月17日
BlackHorse  LV1 2019年7月6日
最近浏览更多
WaZiN7  LV6 4月25日
wangsheng818  LV4 2月29日
微信网友_6802139027345408  LV2 2023年12月31日
李亮  LV19 2023年8月29日
1748938504  LV2 2023年6月30日
mu5532123  LV2 2023年6月15日
qwer123978ca  LV1 2022年12月20日
微信网友_6263159342649344  LV7 2022年12月16日
微信网友_6248713511227392  LV11 2022年12月5日
1743716295  LV4 2022年11月10日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友