0

我已经将我的 GWT 应用程序组装为我在嵌入式 Jetty 中运行的战争文件-

String confFile = System.getProperty("configFilename");
config = new XMLConfiguration(configFilename);
Server server = new Server(8080);
WebAppContext webapp = new WebAppContext();
webapp.setAttribute("config", config);      
webapp.setContextPath("/");
webapp.setWar("file.war");
server.setHandler(webapp);
server.start();
server.join();

我正在尝试在 GWT 服务器端代码中访问我的“配置”对象-

public class MyServiceImpl extends RemoteServiceServlet implements
        MyService {

    config = (XMLConfiguration) this.getThreadLocalRequest().getAttribute("config");

}

在这里,config 始终为空。

我究竟做错了什么?我已经尝试过 config =(XMLConfiguration) this.getServletContext().getAttribute("config");,但这也不起作用-我收到错误-

org.apache.commons.configuration.XMLConfiguration cannot be cast to org.apache.commons.configuration.XMLConfiguration
4

2 回答 2

1

您必须从而ServletContext不是从HttpServletRequest

在你的 RPC 方法中试试这个:

public class MyServiceImpl extends RemoteServiceServlet implements MyService {

  @Override
  public void MyMethod() {
     this.getThreadLocalRequest()
         .getSession().getServletContext()
         .getAttribute("config");
  }

}
于 2013-06-19T07:09:22.477 回答
1

尝试调整您的 Maven 依赖项以显式包含包含 XMLConfiguration 类的 jar,并将其标记为已提供。这将删除类路径中的重复项并解决问题。

于 2013-06-22T19:10:15.237 回答