package framework.startup;
|
|
import org.apache.log4j.Logger;
|
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.event.ContextRefreshedEvent;
|
import org.springframework.web.context.WebApplicationContext;
|
|
import framework.util.excel.ExcelWriter;
|
|
/**
|
* 框架启动
|
*
|
* @author liuyajun, 8384503@qq.com
|
* @date 2016年1月30日
|
* @time 上午9:38:53
|
*/
|
public class FrameStartup implements ApplicationListener<ContextRefreshedEvent> {
|
|
private String uploadPath;
|
public void setUploadPath(String s){
|
this.uploadPath = s;
|
}
|
public String getUploadPath(){
|
return this.uploadPath;
|
}
|
|
private String downloadPath;
|
public void setDownloadPath(String s){
|
this.downloadPath = s;
|
}
|
public String getDownloadPath(){
|
return this.downloadPath;
|
}
|
private String startBean;
|
private WebApplicationContext wac;
|
|
private Logger log = Logger.getLogger(this.getClass());
|
|
@Override
|
public void onApplicationEvent(ContextRefreshedEvent event) {
|
// org.apache.ibatis.logging.LogFactory2.useLog4JLogging();
|
// org.apache.ibatis.logging.LogFactory2.useLog4JLogging();
|
/*
|
* ==null: spring
|
* !=null: springMVC
|
*/
|
if(event.getApplicationContext().getParent() != null){
|
log.info("framework load finished, starting load application!");
|
|
wac = (WebApplicationContext) event.getApplicationContext();
|
FrameUtil.setServletContext(wac.getServletContext());
|
FrameUtil.setWebApplicationContext(wac);
|
|
FrameUtil.setUploadFilePath(uploadPath);
|
FrameUtil.setDownloadFilePath(this.downloadPath);
|
|
log.info("upload file path: "+FrameUtil.getUploadFilePath());
|
|
//设置 excel
|
ExcelWriter.setTempPath(FrameUtil.getDownloadFilePath());
|
|
//启动 bean
|
this.startBeans();
|
|
}
|
}
|
|
private void startBeans(){
|
if(this.startBean ==null){
|
return;
|
}
|
this.startBean = this.startBean.replace("\n", "");
|
this.startBean = this.startBean.replace("\r", "");
|
this.startBean = this.startBean.replace(" ", "");
|
this.startBean = this.startBean.trim();
|
|
if(this.startBean.length() ==0){
|
return;
|
}
|
|
String[] beanIds = this.startBean.split(","); //使用英文逗号分隔
|
|
for(String beanId : beanIds){
|
try{
|
FrameStartBean bean = (FrameStartBean)wac.getBean(beanId);
|
bean.startBean();
|
}catch(Throwable t){
|
log.error("加载启动bean错误", t);
|
}
|
}
|
|
}
|
|
public void setStartBean(String startBean) {
|
this.startBean = startBean;
|
}
|
|
}
|