How to use Google guice with Quartz in Play framework

493 views
Skip to first unread message

Tu Pham Phuong

unread,
Aug 30, 2015, 12:21:37 PM8/30/15
to play-framework
Hi,

Currently my Play application use Guice for Dependency Injection, Guice was great but I have no luck when integrate Quartz for schedule some task. Every classes called from Quartz Job with Guice injected return null. I guess that Play application context and Quart context not share Guice Injector instance. 

I don't have experience with this kind of problem. Can you give me some best pratices to resolve it ?

Thanks you so much !

Dominik Dorn

unread,
Aug 30, 2015, 5:34:26 PM8/30/15
to play-framework
I'm not sure on how you integrated quartz, but when creating the quartz instance, you could inject the current application. 

from there on, you can get the injector manually (applicaiton.injector() ) and do injection as you wish.

Is there a specific reason why you're using Quartz? Since Akka is a fundamental part of Play (and has DI support in 2.4),
you could just use Akka to schedule repetitive tasks... 

Cheers,
Dominik

Alexey Pismenskiy

unread,
Oct 7, 2015, 12:37:04 PM10/7/15
to play-framework
Here is a simple project - Play, Akka, Scala and Google Guice DI. When it starts it schedules a message and then when the actor receives a message it schedules  another message to itself after 5 seconds. 
We use a similar design in one of our applications that need to do some repetitive processes (like DB scans) every {Interval} seconds.

sachin walia

unread,
Oct 7, 2015, 12:47:42 PM10/7/15
to play-framework
Tu Pham,

Quartz is almost in the abandoned state. The triaging of bugs is almost minimal and so is the code check-in activity. I'd recommend against using that and I think if there is any need for scheduling then Akka would be a much better option.

Erol Merdanović

unread,
Oct 8, 2015, 4:23:57 AM10/8/15
to play-framework
You can check https://github.com/enragedginger/akka-quartz-scheduler . I'm using it (with Play 2.2) and it works great.

As Dominik mentioned, either you inject all the you need when creating actors or inject the injector().
Reply all
Reply to author
Forward
Message has been deleted
0 new messages