0

我是 GWT 的初学者。目前我正在尝试在 Spring 中创建一个 Web 应用程序来使用来自REST的数据并在GWT中显示这些详细信息。因此,我为客户端使用 了Spring RestTemplate(发出请求并解组到 java 对象)并将依赖注入留给 Spring(注释)。我已经在具有 GWT-2.4 插件的 Eclipse IDE 中开发了这些东西。

我已尝试在以下案例中启动此 Web 应用程序并面临特定问题。

案例 #1: 当我尝试将应用程序作为 Google Web 应用程序启动时(右键单击 -> 运行方式 -> Google Web 应用程序),没有发生依赖注入,它在属性引用上抛出 NullPointerException。我想当我以 Google App 开始时,它不会使我的上下文加载,因此 Bean-DI 不会发生。

案例 #2: 尝试在 Tomcat 服务器上运行时,我所有的 Bean 创建和依赖注入都在发生,但它没有为 GWT 创建入口点。我没有明确定义任何控制器,因为我认为 GWT 会处理它(就像在 Google Web App Server 中运行一样)。

注意:当我单独运行 GWT 模块(不使用来自 WebService 的数据)时,应用程序运行良好,甚至 Spring RestTemplate 模块在使用 RestService 时也能正常工作,并在 System.Out.println() 中显示值。

核心问题是在 GWT 和 Spring DI 之间进行交互。

项目.gwt.xml:

<inherits name='com.google.gwt.user.User'/>
<inherits name='com.google.gwt.user.theme.clean.Clean'/>

<entry-point class='com.abc.XXXX.gwt.ui.client.XXXX'/>

  <source path='client'/>
  <source path='shared'/>
  <source path='service'/>

应用程序上下文.xml:

<context:component-scan base-package="com.serco.XXXX" />

<context:property-placeholder location="classpath:ClientConfig.properties" />

<bean id="clientSkillService" class="com.abc.XXXX.gwt.ui.service.clientService.impl.ClientSkillService"
    p:hostName="${rest.hostName}"
    p:portNumber="${rest.port}"
    p:userName="${rest.userName}"
    p:password="${rest.password}">
</bean>

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
    <property name="messageConverters">
        <list>
            <bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
                <constructor-arg>
                    <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
                        <property name="classesToBeBound">
                            <list>
                                <value>com.abc.XXXX.gwt.ui.shared.SkillDetailList</value>
                                <value>com.abc.XXXX.gwt.ui.shared.SkillDetail</value>
                            </list>
                        </property>
                    </bean>
                </constructor-arg>
            </bean>
        </list>
    </property>
</bean>

Web.xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    classpath:ApplicationContext.xml
    </param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

请提供您的建议,如何使其工作。

提前致谢。

更新: HTML 文件

 <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>XYZ UI DASHBOARD</title>
    <script type="text/javascript" language="javascript" src="RTSocketDataMonitor/RTSocketDataMonitor.nocache.js"></script>
  </head>
  <body>
    <h1 align="center">XYZ UI DASHBOARD</h1>
    <div align="center" id="grid_tbl"></div>
</body>

入口点类:XXXX.java

public class XXXX implements EntryPoint {
    /*entry point method*/
    public void onModuleLoad() {
        //Creation of DialogBoxes and Panel here
        DialogBox dialogBox;
        //Creation of Composite Derived Class which has DataGrid, DataList, Columnprovider properties to render Details in Table format
        SkillDetailPaginationHandler<SkillDetail> skd = 
        new SkillDetailPaginationHandler<SkillDetail>();
        //added VertiCal Panel in Dialogue Boxes and set it in RootPanel
        RootPanel.get("grid_tbl").add(dialogBox);
    }
}

GWT 编译的 WAR 内容:

  ->Root
      -->XXXX(Folder in the Project Name)
        -->gwt(Folder)
        -->XXXX.nocache.js
        -->host.html
      -->WEB-INF (Folder)
        --> deploy
        --> lib 
        --> web.xml
4

1 回答 1

0

您需要将两个模块分开在单独的项目中。

您需要先编译 GWT 模块,然后将其生成的文件放在主 Web 项目中,然后从 Web 应用程序的控制器调用 GWT 项目的 .html 文件。我希望你理解这一点,它可以帮助你。

于 2012-10-19T10:53:34.620 回答