你确信authService!=null?看一下日志输出吧,看看哪里出错了!

解决方案 »

  1.   

    同上
    你在得到authService后
    看看是否为null在做结论
      

  2.   

    不为空,我设了断点看的,这点我还是知道的。
    我估计是spring 的管理可能被其他的什么东西影响进而出错,但是没见过类似的问题
      

  3.   

    在service层中使用容器的方法建议这样使用:
    import javax.servlet.ServletContext;
    import javax.servlet.ServletContextEvent;import org.springframework.context.ApplicationContext;
    import org.springframework.web.context.support.WebApplicationContextUtils;import com.telestone.web.util.ContextUtil;
    /**
     * 扩展的ContextLoaderListener
     *
     */
    public class MyContextLoaderListener extends
    org.springframework.web.context.ContextLoaderListener { @Override
    public void contextInitialized(ServletContextEvent event) {
    // TODO Auto-generated method stub
    super.contextInitialized(event);

    ServletContext context = event.getServletContext();
            ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
            ContextUtil contextUtil = (ContextUtil) ctx.getBean("contextUtil");
            contextUtil.setContext(ctx);
    }}之后在web.xml中配置自己的ContextLoaderListener <listener>
            <listener-class>
                com.XXXXXXXX.util.MyContextLoaderListener
            </listener-class>
    </listener>可以将MyContextLoaderListener配入容器。通过注入service层bean使用。也可以直接写成静态类。在service层使用。
      

  4.   

    是你的authService执行方法的代码有问题
    而不是spring
      

  5.   

    pizzame :
    对于spring我不是很熟,因为这个项目也是别人架的,web.xml中配了监听,直接用的ContextLoaderListener,方法应该没问题。zqpsswh :
    我在要执行的方法开始就设了断点或者写了打印,都没有走到,而且如果是方法的错,不会有时候错,有时候又不错啊!
      

  6.   

    建议你去看下白衣的这篇文章:在厨房,车顶,草地上使用Spring 
    我只是写了他里面描述的一种方法。