View Full Version : Scheduling Quartz jobs and Application Context
fmourioux
Aug 27th, 2004, 12:39 PM
Hi,
I searching for about 2 hours but no result, is there anyone who knows how can i get the application context of my webapp in order to get managers beans ?
Thanks a lot,
Fabien.
Colin Sampaleanu
Aug 27th, 2004, 12:46 PM
If you are actually in your web-app, you can use WebApplicationContextUtils.getWebApplicationContex t, or getRequiredWebApplicationContext.
Just keep in mind that it's good practice for almost all code to not know about Spring, i.e. only glue layer code should be using methods such as the ones above, with other code being hooked up in IOC fashion using dependency injeciton.
fmourioux
Aug 27th, 2004, 12:56 PM
Hi,
I totaly agree with you Colin, but to use the dependency injection, how can i do.... because i try like this but it doesn't work :
<bean name="sigTraitement" class="org.springframework.scheduling.quartz.JobDetailBea n">
<property name="jobClass">
<value>org.......MonTraitement</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="authentificationManager"><value><ref bean="authentificationManager"/></value></entry>
<entry key="entrepriseManager"><value><ref bean="entrepriseManager"/></value></entry>
<entry key="localisationManager"><value><ref bean="localisationManager"/></value></entry>
</map>
</property>
</bean>
Thanks,
Fabien.
fmourioux
Aug 27th, 2004, 01:42 PM
I was using a wrong usage of map & entry, the good way is :
<bean name="sigTraitement" class="org.springframework.scheduling.quartz.JobDetailBea n">
<property name="jobClass">
<value>org.astre.sig.traitements.MonTraitement</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="utilisateursManager"><ref bean="utilisateursManager"/></entry>
<entry key="authentificationManager"><ref bean="authentificationManager"/></entry>
<entry key="entrepriseManager"><ref bean="entrepriseManager"/></entry>
<entry key="localisationManager"><ref bean="localisationManager"/></entry>
<entry key="utilisateursManager"><ref bean="utilisateursManager"/></entry>
</map>
</property>
</bean>
croudet
Aug 27th, 2004, 01:50 PM
Do you want to get the ApplicationContext from a Job?
If so, do the following:
in your Job:
public void execute(JobExecutionContext context) throws JobExecutionException {
ApplicationContext appContext = (ApplicationContext) context
.getScheduler().getContext().get("applicationContext");
....
}
and add the following property in your Scheduler declaration:
<bean id="Scheduler" class="org.springframework.scheduling.quartz.SchedulerFac toryBean" lazy-init="false">
<property name="applicationContextSchedulerContextKey">
<value>applicationContext</value>
</property>
fmourioux
Aug 27th, 2004, 02:53 PM
Thanks for the information, i don't know right there is i'll pass managers or use the applicationContext, what do u think about this choice ?
Fabien.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.