KK

Kim-'s-Blog.Object-Everything.I'm POJO.

.紀-錄.爲了忘卻的記憶..真的勇士,要敢于直面遇到的問題,敢于正視繁雜的原碼......在實踐中積累!

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  74 Posts :: 1 Stories :: 70 Comments :: 0 Trackbacks
与 数据库 db 相关操作有两种:
1.从DB中读cronExpression
2.Job持久化到数据库
对于1:
Quartz 在Spring中动态设置cronExpression
参考 小刀的blog
http://www.blogjava.net/xiaodaoxiaodao/articles/103437.html 

通过DB加载cronException

一个类是可以的
2个类会出问题

 <bean id="test2" class="cn.edu.hust.mes.service.quartz.Test">  
   
<property name="scheduler" ref="schedulerFactoryBean"/>         
   
</bean>  
     
   
<bean id="test" class="Test">  
   
<property name="scheduler" ref="schedulerFactoryBean"/>  
   
</bean>  
     
   
<bean name="schedulerFactoryBean"  
             
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
          
<property name="triggers">  
               
<list>  
                 
<ref bean="cronTriggerForPLCRead"/>  
                 
<ref bean="cronTrigger"/>  
              
</list>  
         
</property>  
   
         
<property name="configLocation" value="classpath:quartz.properties"/>  
    
</bean> 


Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'schedulerFactoryBean': FactoryBean which is currently in creation returned null from getObject

如果写了拦截器的化 还会报这个错 :

Error creating bean with name 'test2': Bean with name 'test2' has been injected into other beans [schedulerJobDetailForPLCRead] in its raw version as part of a circular reference, but has eventually been wrapped (for example as part of auto-proxy creation). This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.


对于2:
MethodInvokingJobDetailFactoryBean 不能持久化
必须用JobDetailBean 需继承QuartzJobBean  不够pojo
使用MethodInvokingJobDetailFactoryBean的化会报:
org.quartz.JobPersistenceException: Couldn't store job: Unable to serialize JobDataMap for insertion into database because the value of property 'methodInvoker' is not serializable: org.springframework.scheduling.quartz.MethodInvoki ngJobDetailFactoryBean [See nested exception: java.io.NotSerializableException: Unable to serialize JobDataMap for insertion into database because the value of property
API上说了
There's a note in the JavaDoc, I'd presume this might be your problem.
JobDetails created via this FactoryBean are not serializable and thus not suitable for persistent job stores. You need to implement your own Quartz Job as a thin wrapper for each case where you want a persistent job to delegate to a specific service method.
http://www.springframework.org/docs/api/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.html
用MethodInvokingJobDetailFactoryBean不可持久化 除非加个thin wrapper
但查不到任何资料
但愿spring后续版本有好的方案 现在还是老老实实的用JobDetailBean吧

另:
不可用于web action action 用了session等作用域...
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
posted on 2009-03-19 22:19 Kim' 阅读(4216) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 
jj