0

每个请求都尝试创建单例的新实例,但由于它们使用 Application.get() 而失败并出现错误:

There is no application attached to current thread default

相同的代码适用于 WildFly 8.2 和 Wicket 6.20。所以有两个问题:

  1. 每个请求处理程序线程的行为就好像它在自己的 JVM 中运行,而不与其他线程共享静态字段。
  2. 在创建初始请求处理程序线程之后的每个请求处理程序线程都没有附加应用程序。

最小的例子:

package com.example.web;

public class SiteConstants
{
   public static final String CONTEXT_PATH = WebApp.get().getServletcontext().getContextPath() + "/";
}

主页用途

SiteConstants.CONTEXT_PATH

主页的第一个请求有效。第二次调用在另一个线程中加载并失败

WebApp.get().getServletcontext().getContextPath() + "/";

因为 WebApp.get() 抛出

org.apache.wicket.WicketRuntimeException: There is no application attached to current thread default task-1
4

0 回答 0