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;
}
我通过Flex直接调用了这个方法,但是services总是为空。

解决方案 »

  1.   


    package com.phoenix.service;import net.phoenix.comm.AppContext;public interface IService {

    public static AdminInfoService adminInfoService = (AdminInfoService) AppContext.getInstance().getAppContext().getBean("adminInfoTarget");
    }通过一个接口来获取spring的bean,这样就不用action注入了其中AppContext是spring的上下文的单例类,在服务器启动时加载这是AppContext的代码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;
    }
    }
      

  2.   


    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]");
    }
    }
    }
    忘了贴上servlet的监听器,在web.xml里面配置下
      

  3.   

    lowson0 再问你一下
    Constants是什么东西?