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中獲取上下文.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章