Hey Kevin and Cris, 

I got the following exception. Please Click for more detail 
http://stackoverflow.com/questions/39448416/quartz-schduler-with-google-guice-error-injecting-constructor-java-lang-illega
.


On Tuesday, May 1, 2007 at 2:28:28 PM UTC+5:30, Kevin Bourrillion wrote:
>
> Cool.  
>
> I'd simplify just a bit further.
>
> 1. Put @Inject on your GJF constructor, then inject a GJF into your SP 
> instead of the Injector.
> 2. Also have StdSchedulerFactory injected into SP.
> 3. In newJob(), using injector.getInstance(c) instead of using 
> Class.newInstance() followed by injectMembers().  (You may have to cast the 
> result of getJobClass() to a Class<? extends Job> to get this to work.
>
> But it looks good.  (Not that I know anything about Quartz.)
>
> K
>
>
>
> On 5/1/07, ChrisCY <[email protected] <javascript:>> wrote:
>>
>>
>> Hi,
>>
>> I've only used Quartz once, and just for trivial things, but by 
>> looking a bit at the API you can find the org.quartz.spi.JobFactory
>> interface.
>>
>> You can create a custom JobFactory, provide it a reference of the
>> injector and then inject dependencies on the newly created Job object: 
>>
>> public class GuiceJobFactory implements JobFactory {
>>
>>     private final Injector injector;
>>
>>     public GuiceJobFactory(Injector inj) {
>>         injector = inj;
>>     }
>>
>>     public Job newJob(TriggerFiredBundle triggerFiredBundle) throws 
>> SchedulerException {
>>
>>         Job job = null;
>>
>>         try {
>>             job= (Job)
>> triggerFiredBundle.getJobDetail().getJobClass().newInstance();
>>         } catch (Exception ex) {
>>             throw new SchedulerException(ex); 
>>         }
>>
>>         injector.injectMembers(job);
>>
>>         return job;
>>     }
>>
>> You can then provide a new JobFactory to your scheduler through a
>> Provider:
>>
>> public class SchedulerProvider implements Provider<Scheduler> { 
>>
>>     @Inject Injector injector;
>>
>>     public Scheduler get() {
>>         try     {
>>             org.quartz.impl.StdSchedulerFactory factory = new
>> org.quartz.impl.StdSchedulerFactory();
>>             org.quartz.Scheduler scheduler = factory.getScheduler();
>>
>>             scheduler.setJobFactory(new GuiceJobFactory(injector));
>>             return scheduler;
>>         }
>>         catch (SchedulerException ex) {
>>             ...
>>         }
>> }
>>
>> }
>>
>> Finally, you can configure the Scheduler through a Module:
>>
>>
>>
>> bind(Scheduler.class).toProvider(SchedulerProvider.class).asEagerSingleton();
>>
>> I used "asEagerSingleton" to force the instanciation and configuration 
>> of the Scheduler at deployment, and get all the possible configuration
>> errors as soon as possible.
>>
>> I haven't actually used this method (I haven't used Guice for anything
>> yet! :D ) but a small experiment I did seems to work. I hope that 
>> makes sense to you.
>>
>> Let me know if I am diverging form Guice or Quartz filosophy.
>>
>> Christophoros
>>
>>
>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/e18bf550-2372-42f7-9f7c-f436b573e3ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to