Results 1 to 6 of 6

Thread: Scheduling Quartz jobs and Application Context

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    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

  3. #3

    Default

    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.

  4. #4

    Default 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>

  5. #5
    Join Date
    Aug 2004
    Location
    Montreal - Canada
    Posts
    46

    Default

    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>
    Christophe

  6. #6

    Default 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.

Similar Threads

  1. Replies: 4
    Last Post: May 31st, 2011, 07:53 PM
  2. Problem with Quartz and Spring (durable jobs)
    By keithc in forum Container
    Replies: 4
    Last Post: Nov 1st, 2006, 02:17 PM
  3. Quartz - Statefull Jobs
    By nandhusriram in forum Container
    Replies: 1
    Last Post: Sep 7th, 2005, 01:11 PM
  4. Getting a resource using application context?
    By todds in forum Container
    Replies: 2
    Last Post: Oct 20th, 2004, 11:52 AM
  5. Desktop application, strange behaviour
    By innovate in forum Container
    Replies: 2
    Last Post: Sep 24th, 2004, 04:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •