appfuse + Quartz

 在配置了appfuse + Quartz 之后,本来测试的时候只是打印个测试语句而已,所以没有发现该问题,当进行作业调度使用到相关的Manager的时候,才发现Quartz 是独立的线程,无法获取到appfuse里的 ServletActionContext ,报出如下异常:

java.lang.NullPointerException
 at com.opensymphony.webwork.ServletActionContext.getServletContext(ServletActionContext.java:104)
 at com.zrrt.wapportal.service.impl.BaseManager.getServletContext(BaseManager.java:75)
 at com.zrrt.wapportal.service.impl.BaseManager.getManager(BaseManager.java:87)
 at com.zrrt.wapportal.service.impl.UserManagerImpl.calculateWap(UserManagerImpl.java:167)
 at com.zrrt.wapportal.service.impl.UserManagerImpl.dailyStatistic(UserManagerImpl.java:158)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.ja
va:155)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
 at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityIntercept
or.java:80)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
 at $Proxy2.dailyStatistic(Unknown Source)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:248)
 at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal
(MethodInvokingJobDetailFactoryBean.java:165)
 at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:66)
 at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
 at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)

 

  后经过请教高人,一下就解决了,解决方案可能有多种,我目前的解决方式是在项目里构建一个ContextManager(假设就叫这个名字),然后在StartupListener中为ContextManager设置当前的上下文对象,然后在Quartz启动并使用Manager的时候,从ContextManager中获取上下文.

你可能感兴趣的:(quartz,manager,测试,Appfuse,作业)