标签:java hibernate encoding myeclipse java web
在程序中,有些数据我们希望在程序启动的时候就准备好,并且只准备一次,放在application作用域中,这时候,我们通常会用Listener来准备这些数据。但是,用Listener准备application作用域的数据,在获取容器的时候会有一些注意事项。public class InitListener implements ServletContextListener { public void contextInitialized(ServletContextEvent sce) { // 获取容器与相关的Service对象 ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()); PrivilegeService privilegeService = (PrivilegeService) ac.getBean("privilegeServiceImpl"); // 准备数据:topPrivilegeList List<Privilege> topPrivilegeList = privilegeService.findTopList(); sce.getServletContext().setAttribute("topPrivilegeList", topPrivilegeList); System.out.println("------------> 已准备数据 <------------"); // 准备数据:allPrivilegeUrls Collection<String> allPrivilegeUrls = privilegeService.getAllPrivilegeUrls(); sce.getServletContext().setAttribute("allPrivilegeUrls", allPrivilegeUrls); System.out.println("------------> 已准备数据allPrivilegeUrls <------------"); } public void contextDestroyed(ServletContextEvent arg0) { }
标签:java hibernate encoding myeclipse java web
原文地址:http://blog.csdn.net/u013370108/article/details/46328277