耐久化されたQuartzとSpringを統合した時に出会ういくつかのピットを記録します.
4731 ワード
仕事のために、Qartzはデータベースの中で恒久化しなければならないので、毎日の明け方の定時任務を開いて、任務の処理jobの中でまたspring管理のservice種類に使わなければならなくて、だからいくつかの小さい問題に出会って、これによって記録をします. spring-quartzファイルを構成する場合、使用するMethodInvoking JobDetail FactoryBenは、jobDetail を作成します.
Qartzは耐久化を使用しているため、Job StoreTXの記憶方式はNot Serializable Exceptionの異常を引き起こしています.Googleは、MethodInvoking JobDetail FactoryBeanが序文化されていないことを知っています.JobDetail FactoryBen方式を使って作成し、jobクラスでQuartzJobBenを継承し、jobDetailを作成すれば、間違いがありません.以下のとおりです spring管理のserviceに注入されたサービスは、jobタイミング操作において、直接@Resourceに を注入する.
Null PointerExceptionの空のポインターの異常を直接報告した後、Googleは自分の文脈があると分かりました.springは管理できません.もちろん自動的に注入できません.spring-quartzの配置ファイルに直接このserviceをjobDataMapに追加しました.
これは永続化していないquartzのservice注入問題を解決できる方法です.しかし、私の配置は恒久化が必要です.つまり、データベースを保存する必要があります.しかし、springのserviceの最下層はSerializableインターフェースを実現していないので、Not Serializable Exceptionを間違えました.自分でSerializableを実現してもだめです.その後、Googleは長い間、関連の方法を書き直したり、session factoryを使ったりしましたが、本人の能力はまだだめです.最後にあるブロガーがspringのcontextをquartzに注入するのを見ました. Schduler FactoryBeanを構成するとき、springコンテキスト を注入することができます.
ここまで来たら、私の速いGoogleの一日の難題を解決しました.今は大体このように分かります.問題を解決して記録して印象を強めます.
Qartzは耐久化を使用しているため、Job StoreTXの記憶方式はNot Serializable Exceptionの異常を引き起こしています.Googleは、MethodInvoking JobDetail FactoryBeanが序文化されていないことを知っています.JobDetail FactoryBen方式を使って作成し、jobクラスでQuartzJobBenを継承し、jobDetailを作成すれば、間違いがありません.以下のとおりです
——————————————————————————————————————————————————————————————————————————————————
// QuartzJobBean
@DisallowConcurrentExecution
public class TimeQueryContract extends QuartzJobBean {
/**
* Execute the actual job. The job data map will already have been
* applied as bean property values by execute. The contract is
* exactly the same as for the standard Quartz execute method.
*
* @param context
* @see #execute
*/
@Override
protected void executeInternal(JobExecutionContext context) {...}
}
Null PointerExceptionの空のポインターの異常を直接報告した後、Googleは自分の文脈があると分かりました.springは管理できません.もちろん自動的に注入できません.spring-quartzの配置ファイルに直接このserviceをjobDataMapに追加しました.
これは永続化していないquartzのservice注入問題を解決できる方法です.しかし、私の配置は恒久化が必要です.つまり、データベースを保存する必要があります.しかし、springのserviceの最下層はSerializableインターフェースを実現していないので、Not Serializable Exceptionを間違えました.自分でSerializableを実現してもだめです.その後、Googleは長い間、関連の方法を書き直したり、session factoryを使ったりしましたが、本人の能力はまだだめです.最後にあるブロガーがspringのcontextをquartzに注入するのを見ました.
————————————————————————————————————————————————————————————————————————————————————————
// job spring service
@DisallowConcurrentExecution
public class TimeQueryContract extends QuartzJobBean {
/**
* Execute the actual job. The job data map will already have been
* applied as bean property values by execute. The contract is
* exactly the same as for the standard Quartz execute method.
*
* @param context
* @see #execute
*/
@Override
protected void executeInternal(JobExecutionContext context) {
System.out.println(" ...");
try {
// spring
ApplicationContext applicationContextKey = (ApplicationContext) context.getScheduler().getContext().get("applicationContextKey");
// service
ContractSignServiceImpl contractSignService = (ContractSignServiceImpl) applicationContextKey.getBean("contractSignServiceImpl");
System.out.println(contractSignService.queryDate().toString());
} catch (SchedulerException e) {
e.printStackTrace();
}
}
}
最後の解決方法の持ち主ここまで来たら、私の速いGoogleの一日の難題を解決しました.今は大体このように分かります.問題を解決して記録して印象を強めます.