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.
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.
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.
Colin Sampaleanu
SpringSource - http://www.springsource.com
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 :
Thanks,Code:<bean name="sigTraitement" class="org.springframework.scheduling.quartz.JobDetailBean"> <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>
Fabien.
I was using a wrong usage of map & entry, the good way is :
Code:<bean name="sigTraitement" class="org.springframework.scheduling.quartz.JobDetailBean"> <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>
Do you want to get the ApplicationContext from a Job?
If so, do the following:
in your Job:
and add the following property in your Scheduler declaration:Code:public void execute(JobExecutionContext context) throws JobExecutionException { ApplicationContext appContext = (ApplicationContext) context .getScheduler().getContext().get("applicationContext"); .... }
Code:<bean id="Scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false"> <property name="applicationContextSchedulerContextKey"> <value>applicationContext</value> </property>
Christophe
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.