Announcement Announcement Module
Collapse
No announcement yet.
Scheduling Quartz jobs and Application Context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scheduling Quartz jobs and Application Context

    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.

  • #2
    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.

    Comment


    • #3
      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 :

      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>
      Thanks,

      Fabien.

      Comment


      • #4
        sorry ...

        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>

        Comment


        • #5
          Do you want to get the ApplicationContext from a Job?
          If so, do the following:

          in your Job:
          Code:
          public void execute&#40;JobExecutionContext context&#41; throws JobExecutionException &#123;      
              ApplicationContext appContext = &#40;ApplicationContext&#41; context
                    .getScheduler&#40;&#41;.getContext&#40;&#41;.get&#40;"applicationContext"&#41;;
             ....
          &#125;
          and add the following property in your Scheduler declaration:
          Code:
          <bean id="Scheduler" 	class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false">
            <property name="applicationContextSchedulerContextKey">
               <value>applicationContext</value>
           </property>

          Comment


          • #6
            Thanks

            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.

            Comment

            Working...
            X