我是GWT的初学者。目前我正在尝试在Spring中创建一个Web应用程序来使用 REST 中的数据,并在 GWT 中显示这些详细信息。因此,我使用 Spring RestTemplate 作为客户端(向java Object发出请求和解组)并将依赖注入留给Spring(注释)。我已经在 Eclipse IDE中开发了这些东西,它有GWT-2.4插件。
我已尝试在以下案例中启动此Web应用程序并面临指定的问题。
案例#1: 当我尝试将应用程序作为Google Web应用程序(右键单击 - >运行为 - > Google Web应用程序)启动时,不会发生依赖项注入,它会在属性引用上抛出NullPointerException。我想当我开始使用Google App时,它不会使我的Context加载,因此Bean-DI没有发生。
案例#2: 在尝试在Tomcat服务器上运行时,我的所有Bean创建和依赖注入都在发生,但它没有为GWT创建一个EntryPoint。我没有明确定义任何Controller,因为我想到GWT会照顾它(就像在Google Web App Server中运行一样)。
注意:当我单独运行GWT模块(不消耗来自WebService的数据)时,应用程序正常运行,甚至Spring 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
答案 0 :(得分:0)
您需要在单独的项目中分离两个模块。
首先需要编译GWT模块,然后将其生成的文件放在主Web项目中,然后从Web应用程序的控制器调用GWT项目的.html文件。我希望你能理解这一点并帮助你。