ich die DI bin mit meiner App im Play 2.5 zuzugreifen:die aktuelle App im Play 2.5.2
import com.google.inject.{Inject, Provider}
import play.api.mvc._
import play.api.Application
class ApplicationController @Inject()(p: Provider[Application]) extends Controller {
implicit lazy val app = p.get()
println(app.hashCode()+"") // Random line to use the injected app
}
Ich erhalte die folgende Fehlermeldung:
ProvisionException: Unable to provision, see the following errors:
1) Tried proxying play.api.Application to support a circular dependency, but circular proxies are disabled. ...
ich auf das ging Play Migration guide: https://www.playframework.com/documentation/2.5.x/Migration25#Handling-legacy-components
und tat wie sie sagen, um zirkuläre Abhängigkeit zu vermeiden, aber ich habe immer noch diesen Fehler.
Ich habe auch eine Variable namens disableCircularProxies gefunden, die ich derzeit nicht benutze (http://google.github.io/guice/api-docs/latest/api-diffs/changes/docdiffs_com.google.inject.html), da ich mir nicht sicher bin, wie ich das mache und sehr wenig Informationen darüber finde.
Irgendeine Idee, wie man diesen zirkulären Abhängigkeitsfehler löst?
Hier ist der vollständige Stack-Trace:
Tried proxying play.api.Application to support a circular dependency, but circular proxies are disabled.
at play.api.DefaultApplication.class(Application.scala:221)
while locating play.api.DefaultApplication
while locating play.api.Application
at myCustomProject.controllers.ApplicationController.<init>(ApplicationController.scala:9)
while locating myCustomProject.controllers.ApplicationController
for parameter 1 at router.Routes.<init>(Routes.scala:31)
while locating router.Routes
while locating play.api.inject.RoutesProvider
while locating play.api.routing.Router
for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:200)
while locating play.api.http.JavaCompatibleHttpRequestHandler
while locating play.api.http.HttpRequestHandler
for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:221)
at play.api.DefaultApplication.class(Application.scala:221)
while locating play.api.DefaultApplication
while locating play.api.Application
Letztlich soll ich nicht diese Provider verwendet [Anwendung], sondern die Konfiguration, Umwelt, ... aus dem App. Es ist nur, dass nach dem Dokument, ich in der Lage sein sollte, dass das funktioniert.
Sie sollten die Anwendung direkt injizieren können, keine Notwendigkeit, den Anbieter injizieren, das heißt '@Inject() (val Anwendung: Anwendung)' sollte gut funktionieren. – alextsc
Leider gibt es mir den gleichen Fehler. Laut dem Dokument: "Beachten Sie, dass Sie in diesem Fall normalerweise einen Provider [Anwendung] verwenden möchten, um zirkuläre Abhängigkeiten zu vermeiden." – Scipion
Ist dies ein regelmäßiger Controller? Gibt die Fehlermeldung an, wo die andere Abhängigkeit benötigt wird? – rethab