67,538
社区成员
发帖
与我相关
我的任务
分享
private ServiceImplPublicQuery services = null;
public int getTotalCount() {
int returnValue = 38;
return returnValue;
}
public ServiceImplPublicQuery getServices() {
return services;
}
public void setServices(ServiceImplPublicQuery services) {
this.services = services;
}
package net.phoenix.listener;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import net.phoenix.comm.AppContext;
import net.phoenix.comm.Constants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
/**
* 系统启动将要运行的类
*
* @author 咖啡
*
*/
public class StartupListener extends ContextLoaderListener implements ServletContextListener {
private static final Log log = LogFactory.getLog(StartupListener.class);
/**
* 设置程序根目录
*/
public void contextInitialized(ServletContextEvent event) {
String rootpath = event.getServletContext().getRealPath("/");
if (rootpath != null) {
rootpath = rootpath.replaceAll("\\\\", "/");
} else {
rootpath = "/";
}
if (!rootpath.endsWith("/")) {
rootpath = rootpath + "/";
}
Constants.ROOTPATH = rootpath;
if (log.isDebugEnabled()) {
log.debug("initializing context...");
}
super.contextInitialized(event);
ServletContext context = event.getServletContext();
String daoType = context.getInitParameter(Constants.DAO_TYPE);
if (daoType == null) {
log.warn("No 'daoType' context carameter, using hibernate");
daoType = Constants.DAO_TYPE_HIBERNATE;
}
Map config = (HashMap) context.getAttribute(Constants.CONFIG);
if (config == null) {
config = new HashMap();
}
config.put(Constants.DAO_TYPE, daoType);
context.setAttribute(Constants.CONFIG, config);
if (log.isDebugEnabled()) {
log.debug("daoType: " + daoType);
log.debug("populating drop-downs...");
}
setupContext(context);
}
// 登录加载spring的context
public static void setupContext(ServletContext context) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
AppContext.setContext(ctx);
if (log.isDebugEnabled()) {
log.debug("drop-down initialization complete [OK]");
}
}
}
package com.phoenix.service;
import net.phoenix.comm.AppContext;
public interface IService {
public static AdminInfoService adminInfoService = (AdminInfoService) AppContext.getInstance().getAppContext().getBean("adminInfoTarget");
}
package net.phoenix.comm;
import org.springframework.context.ApplicationContext;
/**
* 单例类,用于设置,获取Spring上下文的配置信息
*/
public class AppContext {
private static AppContext instance;
private static ApplicationContext appContext;
private AppContext() {
}
public synchronized static AppContext getInstance() {
if (instance == null) {
instance = new AppContext();
}
return instance;
}
public static void setContext(ApplicationContext setContext) {
appContext = setContext;
}
public ApplicationContext getAppContext() {
return appContext;
}
}