タスクを実行するスレッドを作成しようとしていて、特定の時間(たとえば100秒)内に終了しない場合は例外をスローします。現在私は、タスクをrunnable
オブジェクトにカプセル化し、ExecutorService
とFuture
クラスを使用してタイムアウトを実行することで、これを実行しようとしています。私は自分のWebサービスを起動したときしかし、私はこの例外を取得:Spring Webサーバでタイムアウトを指定してタスクを実行するためのスレッドを作成する
java.util.concurrent.ExecutionException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.localhostInterpolatorHealthCheck': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:202)
私はそれはあなた自身のスレッドを定義し、春にスレッドを始めるためにそれらを起動するのと同じくらい簡単ではないことをオンラインで読むので、私は行う方法を疑問に思ってこの?私は何が欠けていますか?
例外メッセージによると、スケジュールされたスレッドの実行がリクエストスコープ内にない間に、リクエストスコープのSpring Beanを使用しています。 – AdamSkywalker
@AdamSkywalker実行可能ファイルを拡張し、そのクラスをスレッド内にカプセル化し、 'Future'と' ExecutorService'を使って時間制限付きのコードブロックを行うクラスを作成しています。コードブロックは、一連の正常性テストを実行します。新しいクラスはそれをサポートするBeanを持っていません(私はそれが必要とは思わなかった)、これはおそらくどこが間違っているのでしょうか? –
私は十分な情報を持っていない、私はそのコードが何とか豆を使用して参照してください。あなたは完全なスタックトレースを持っていますか?これで、例外の先頭だけが表示されます。 – AdamSkywalker