Bathiya Priyadarshana
Bathiya Priyadarshana

Reputation: 1405

Play Framework 2.6.20 PlayService Plugin Project ApplicationLifecycle support

I was trying out the new PlayService sbt plugin introduced with Play 2.6 (my exact Play version is 2.6.20), and I want to use the stop hook of the application as mentioned in the below link with this PlayService plugin based Play project.

https://www.playframework.com/documentation/2.6.x/JavaDependencyInjection#Stopping/cleaning-up

My code looks as below,

@Singleton
public class LtrBootStrapper {

    @Inject
    public LtrBootStrapper(ApplicationLifecycle applicationLifecycle) {
        //Other functionalities

        //Actual components to stop inside stop hook to be added later on
        applicationLifecycle.addStopHook(() -> CompletableFuture.completedFuture(null));
    } 
}

However, when I start the application, it fails to start with the following exception.

1 error] at play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:186) at play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:124) at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:241) at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:138) at akka.stream.impl.fusing.MapAsyncUnordered$$anon$26.onPush(Ops.scala:1304) at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:519) at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:482) at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:378) at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:588) at akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:472) Caused by: com.google.inject.CreationException: Unable to create injector, see the following errors:

1) No implementation for play.inject.ApplicationLifecycle was bound.
while locating play.inject.ApplicationLifecycle for the 1st parameter of com.mycompany.ltr.startup.LtrBootStrapper.(LtrBootStrapper.java:22)

Does this mean PlayService applications does not support ApplicationLifecycle? If so what is the alternative for stop hook equivalent in PlayService applications?

Thanks in advance.

Upvotes: 0

Views: 290

Answers (1)

ApplicationLifecycle is provided by play.inject.BuiltInModule. This is provided by the java-core subproject, which PlayMinimalJava (and PlayJava) automatically adds a dependency on, but PlayService does not.

To fix this, explicitly add the dependency to your build.sbt, like this:

libraryDependencies += javaCore

Upvotes: 1

Related Questions