---
title: "WEB项目启动加载的实现方式整理"
author: "saintsaya"
date: "2013-12-19T17:15:37Z"
tags: []
categories: ["编程语言"]
slug: "web"
draft: false
lastmod: "2013-12-19T17:15:37Z"
id: 1992290
url: "https://kangrui.iteye.com/blog/1992290"
---

\[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]