WEB项目启动加载的实现方式整理
[b]方法一:[/b] 实现org.springframework.beans.factory.config.BeanPostProcessor接口: [code="java"]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; } } [/code] 在spring配置文件中添加: [code="xml"] [/code] [b]方法二:[/b] 实现org.springframework.beans.factory.InitializingBean接口: [code="java"]public class SysInitBean implements InitializingBean, ServletContextAware { public void afterPropertiesSet() throws Exception { } @Override public void setServletContext(ServletContext servletContext) { } } [/code] 在spring配置文件中添加: [code="xml"] [/code] [b]方法三:[/b] 实现javax.servlet.ServletContextListener: [code="java"]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"); } } [/code] 在web.xml中添加listener: [code="xml"] ***.***.RedisInitListener [/code]