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; } }
<bean name="code">public class SysInitBean implements InitializingBean, ServletContextAware { public void afterPropertiesSet() throws Exception { } @Override public void setServletContext(ServletContext servletContext) { } }
<bean name="code">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"); } }
<listener> <listener-class>***.***.RedisInitListener</listener-class> </listener>