Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with inject dependencies service in job #3

Open
juanfaustoperalta opened this issue Jan 3, 2018 · 4 comments
Open

Problem with inject dependencies service in job #3

juanfaustoperalta opened this issue Jan 3, 2018 · 4 comments

Comments

@juanfaustoperalta
Copy link

juanfaustoperalta commented Jan 3, 2018

Hi, sorry for my English.
I want to use a task lib in my projec with Scala 2.12 and Play 2.6. When I set up and inject dependencies of play in it, it does not work because of the error: Could not find the default constructor with no parameters in: myClass for example: class Person @Inject()(actorSystem: ActorSystem, val carService: carService) extends AbstractConfigurationJob(actorSystem). The TestJobs do work correctly. Any suggestion?

Thanks

@zuoky
Copy link

zuoky commented Jan 28, 2018

Same issue here

@zuoky
Copy link

zuoky commented Jan 28, 2018

I surrendered to the problem by below:

class SmsNotificationDaily @Inject()(actorSystem: ActorSystem)
extends AbstractAnnotatedJob(actorSystem) {

@Inject() var cloudResourceHandler: CloudResourceHandler = _
@Inject() var ec: BlockingExecutionContext = _

...

}

(but Guice throws a lot exceptions complaining to the dependencies, I am still search solutions for it here)

@martor
Copy link

martor commented Mar 27, 2018

I'm running into the same issue.

@zuoky your workaround unfortunately results in java.lang.NullPointerException: null when I try call a function on the injected service.

@aohanglove
Copy link

This library is not suitable for DI. You can see the class JobClassLoader, and it use reflection to get instance of out user-defined job, not with DI.

I think the only way is to get the instance from DI by Play.current.injector.getInstance, but it is depreted after play 2.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants