package com.crm.application;
import java.sql.Connection;
import java.sql.Statement;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.context.ServletContextAware;
import com.crm.application.load.RedisLoadThread;
import com.crm.h2.H2Manager;
import com.crm.h2.load.H2LoadThread;
public class CrmApplication implements InitializingBean, ServletContextAware{
 
 private Log log = LogFactory.getLog(CrmApplication.class);
 
 public void setServletContext(ServletContext arg0) {
  log.info("-------------------------【Crm系统初始化】开始-------------------------");
  try {
   
   log.info("----------【H2处理】----------");
   Connection conn = H2Manager.getConnection();
   Statement stmt = conn.createStatement();
   stmt.executeUpdate(H2Manager.getCreateCrmTranslateKindSql());
   stmt.executeUpdate(H2Manager.getCreateCrmTranslateMapSql());
   conn.close();
   new H2LoadThread().start();
   
   log.info("----------【Redis加载】----------");
   new RedisLoadThread().start();
   
  } catch (Exception e) {
   e.printStackTrace();
  }
 
  log.info("-------------------------【Crm系统初始化】结束-------------------------");
 }
 
 
 //InitializingBean
 public void afterPropertiesSet() throws Exception {
  log.info("afterPropertiesSet...");
 }
 
}
?<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="  
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd  
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd  
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd  
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd  
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
default-lazy-init="true">
<context:component-scan base-package="com.crm.service" />
<context:component-scan base-package="com.crm.repository" />
<bean id="CrmContext" class="com.crm.application.CrmContext" ></bean>
<bean id="CrmApplication" class="com.crm.application.CrmApplication" ></bean>
?这句话导致的
(4.2)实现ServletContextAware
可以获得servletcontext
(4.3)default-lazy-init="true":经常性的拷贝,也不理解这句话的含义
详细内容参考:http://thinkerandthinker.iteye.com/blog/1337706
在spring初始化bean的时候,如果该bean是实现了InitializingBean接口,并且同时在配置文件中指定了init-method,系统则是先调用afterPropertiesSet方法,然后在调用init-method中指定的方法。
原文:http://toknowme.iteye.com/blog/2236027