我有一个 Wicket 应用程序,我正在尝试实现可以远程更改的单独配置。无论如何,这就是最终目标。
我想要做的是设置 Cayenne 通过手动启动它来工作,而不是使用 web.xml 文件。我尝试了很多不同的东西,但我不确定我是否完全理解上下文是如何应用于所有线程的。
我尝试在我的 Application 类中创建一个 ServerRuntime。我还尝试了每个页面使用的自定义 BasePage 类。我可以通过在 BasePage 上执行以下操作来使其工作,但它是不一致的:
public class BasePage ....
public static ServerRuntime runtime = new ServerRuntime("cayenne-config.xml");//This is in my BasePage class, but I've also tried this in the Application class
@Override
protected void init() {
BaseContext.bindThreadObjectContext(Application.runtime.getContext());//This is in my BasePage class
}
就像我说的那样,这种方法有效,但并不一致。我不断收到错误
BaseContext.getThreadObjectContext();
错误是这样的:
java.lang.IllegalStateException: Current thread has no bound ObjectContext.
我似乎找不到太多关于此的信息。我尝试做这样的事情,并使用这些来访问运行时,但没有任何东西能始终如一地工作。
WebUtil.setCayenneRuntime(this.getServletContext(), runtime);
BaseContext.bindThreadObjectContext(WebUtil.getCayenneRuntime(((Application)getApplication()).getServletContext()).getContext());
任何帮助将不胜感激。