当前位置: 代码迷 >> Web前端 >> WEB项目启动加载的实现模式整理
  详细解决方案

WEB项目启动加载的实现模式整理

热度:348   发布时间:2013-12-22 15:06:55.0
WEB项目启动加载的实现方式整理
方法一:
实现org.springframework.beans.factory.config.BeanPostProcessor接口:
public class InstantiationTracingBeanPostProcessor implements BeanPostProcessor {    
      
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {      
        return bean;    
    }      
      
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {      
        return bean;      
    }      
}  

在spring配置文件中添加:
<bean class="***.***.InstantiationTracingBeanPostProcessor"/>  


方法二:
实现org.springframework.beans.factory.InitializingBean接口:
public class SysInitBean implements InitializingBean, ServletContextAware {  
    public void afterPropertiesSet() throws Exception {  
    }  
  
    @Override  
    public void setServletContext(ServletContext servletContext) {  
    }  
}  

在spring配置文件中添加:
<bean class="***.***.SysInitBean"/>  


方法三:
实现javax.servlet.ServletContextListener:
public class RedisInitListener implements ServletContextListener {  
  
    @Override  
    public void contextDestroyed(ServletContextEvent sce) {  
  
    }  
  
    @Override  
    public void contextInitialized(ServletContextEvent sce) {  
        //WebApplicationContext wa = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());  
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");         
    }  
}  

在web.xml中添加listener:
<listener>    
    <listener-class>***.***.RedisInitListener</listener-class>    
</listener>
  相关解决方案