Guiceを使用して静的オブジェクト(リアルタイムセンサー監視オブジェクト)をApplication.javaに挿入するPlay2アプリケーションがあります。
controllers.Application:
public class Application extends Controller {
@Inject static MonitorService monitorService;
...
}
module.Dependencies:
public class Dependencies {
....
@Provides
@Singleton
public MonitorService getMonitorService(final MonitorFactory factory) {
return new MonitorService(factory){
@Override
public MonitorService(Factory factory){
return factory.getMonitor();
}
}
}
}
私の問題は、Playアプリケーションが終了しているときに、ファクトリまたはモニターオブジェクトにアクセスして、正常にシャットダウンすることです。GlobalSettings.onStopにフックすることを検討しましたが、 Play.Applicationオブジェクトから参照を抽出する方法がわかりません。MonitorServiceをGlobalクラスに挿入しようとしましたが、nullオブジェクトが返されるため、この段階でDependenciesオブジェクトが破棄されたと想定しています。
私はまた、このアプローチが完全に間違っているかもしれないことを知っています;)
どんな助けでも大歓迎です。