我是GWT的初學者。目前我正試圖在Spring中創建一個Web應用程序,以便使用來自REST的數據,並在GWT中顯示這些詳細信息。所以,我使用Spring RestTemplate作爲客戶端(向java對象提出請求和解組),並將依賴注入留給Spring(註解)。我已經在Eclipse IDE中開發了這些具有GWT-2.4插件的東西。無法將GWT與Spring RestTemplate實現集成
我試圖在下面的案例中啓動這個Web應用程序並面對指定的問題。
案例#1: 當我試圖啓動應用程序,谷歌的Web應用程序(右鍵 - >運行方式 - >谷歌Web應用程序),依賴注入是不會發生,這引發NullPointerException異常上屬性參考。我想當我開始作爲谷歌應用程序,它不會使我的上下文加載,因此Bean-DI不會發生。
案例#2: 在嘗試Tomcat服務器上運行,我所有的Bean創建和依賴注入正在發生,但它不會使GWT的入口點。我沒有明確定義任何控制器,因爲我想到GWT會照顧它(就像在Google Web App Server中運行一樣)。
注:該應用程序是正常使用時我運行GWT模塊seperately(未從WebService的消耗數據),甚至彈簧RestTemplate模塊在工作作爲足夠好的消耗RestService並顯示在System.out的值.println()。
核心問題是在GWT和Spring DI之間進行交互。
Project.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'/>
的applicationContext.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
感謝您的回覆。您能否詳細說明一下,我們需要在「主Web項目」中放置GWT編譯項目(我假設它是WAR內容)?欣賞你是否舉了一些例子。 – omega
現在我沒有它的例子。您可以在WEB-INF目錄下創建一個新文件夾或與之平行。您只需使用具有主要html文件或GWT的路徑並從您的控制器調用它。 –
我編譯了GWT模塊並放置在WEB-INF文件夾旁邊。當我啓動tomcat服務器時,它呈現HTML文件(靜態內容),但不是作爲GWT應用程序。 (其實我有DataGrid這將調度到'OnModuleLoad()'方法這個HTML) 我在這裏失蹤了什麼? (已更新此文章中的HTML文件) – omega