我用了个监听类,实现接口ServletContextListener。
在tomcat启动时把一些初始数据存进application里:
request.getServletContext().setAttribute("item",item);
但是这些数据会更新的,我想用spring quartz定时更新一下这些内容,
现在不知道这个定时的类该怎么拿到 ServletContext,是不是也要实现什么接口或者继承什么类才可以呢? 

解决方案 »

  1.   

    试试看ContextLoader.getCurrentWebApplicationContext().getServletContext()web.xml里加个
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
      

  2.   

    问题的重点不是quartz,是ServletContext
      

  3.   

    楼主试过我的方法了吗?不出意外在任何地方都可以获取到ServletContext
      

  4.   

    因为我已经在web。xml中 org.springframework.web.context.ContextLoaderServlet
    所以和你那个有冲突了,报了个异常说web。xml文件里有多个contextLoader我现在的做法是,自己的listener,然后实现ServletContextListener然后再contextInitialized方法里,InitSysInfoDao initSysInfoDao = (InitSysInfoDao)ApplicationContextUtil.getBean("initSysInfoDao"); ApplicationContextUtil里能拿到全部的BEAN
      

  5.   

    对spring quartz很熟悉,很快就能找出解决方案!
    你试过2楼的方法啦吗?
      

  6.   

    现在我在写个定时任务定时刷新放在application里的值应该就可以了
      

  7.   

    你既然都加载了ContextLoaderListener,直接在你的quartz实现里用。ContextLoader.getCurrentWebApplicationContext().getServletContext();