无法将GWT与Spring RestTemplate实现集成在一起 [英] could not integrate GWT with Spring RestTemplate implementation

查看:139
本文介绍了无法将GWT与Spring RestTemplate实现集成在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我试图在下面的例子中启动这个Web应用程序,面临指定的问题。



案例#1:
当我尝试以Google Web Application的形式启动应用程序时单击 - >运行方式 - > Google Web应用程序),依赖注入不会发生,它在属性引用上抛出NullPointerException。我猜,当我以Google应用程序开始时,它并不会让我的上下文加载,因此Bean-DI不会发生。



案例2: / strong>
尝试在Tomcat服务器上运行时,我所有的Bean创建和依赖注入都在发生,但它并没有为GWT创建一个EntryPoint。我没有明确定义任何控制器,因为我想到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'/> 
<继承了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/>

p:hostName =$ {rest.hostName }
p:portNumber =$ {rest.port}
p:userName =$ {rest.userName}
p:password =$ {rest.password}>
< / bean>

< bean id =restTemplateclass =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>
<值> com.abc.XXXX.gwt.ui.shared.SkillDetailList< /值>
<值> com.abc.XXXX.gwt.ui.shared.SkillDetail< /值>
< / 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>

请提供您的建议,以及如何使其发挥作用。



此致敬礼。


$ b

更新: HTML文件

 < head> 
< meta http-equiv =content-typecontent =text / html; charset = UTF-8>
< title> XYZ UI DASHBOARD< / title>
< script type =text / javascriptlanguage =javascriptsrc =RTSocketDataMonitor / RTSocketDataMonitor.nocache.js>< / script>
< / head>
< body>
< h1 align =center> XYZ UI DASHBOARD< / h1>
< div align =centerid =grid_tbl>< / div>
< / body>

入口点类:XXXX.java

  public class XXXX implements EntryPoint {
/ *入口点方法* /
public void onModuleLoad(){
//在这里创建对话框和面板
DialogBox dialogBox;
//创建具有DataGrid,DataList,ColumnProvider属性的复合派生类以Table格式呈现Details
SkillDetailPaginationHandler< SkillDetail> skd =
新SkillDetailPaginationHandler< SkillDetail>();
//在对话框中添加VertiCal Panel,并将其设置在RootPanel
RootPanel.get(grid_tbl).add(dialogBox);





$ b

GWT编译的WAR内容:

   - >根目录
- > XXXX(项目名称中的文件夹)
- - > gwt(文件夹)
- > XXXX.nocache.js
- > host.html
- > WEB-INF(文件夹)
- - >部署
- > lib
- > web.xml


解决方案

单独的项目。

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


I'm a beginner in GWT. Currently I'm trying to create an Web application in Spring to consume data from REST and displays those details in GWT. So, I used Spring RestTemplate for client(to make a request and unmarshalling to java Object) and left the Dependency Injection to Spring(annotation). I have developed these entire thing in Eclipse IDE which has GWT-2.4 plugin.

I have tried to start this Web Application in below Cases and facing the specified issues.

Case #1: When i'm trying to start the application as Google Web Application (Right Click -> Run as -> Google Web Application), The dependency injection is not happening, It throws NullPointerException on an Property reference. I guess when i'm starting as Google App it doesn't makes my Context Loaded and thus Bean-DI is not happening.

Case #2: While trying to Run on Tomcat Server, all my Bean Creation and Dependency Injection are happening, but it doesn't make an EntryPoint for GWT. I have not defined any Controller explicitly, because i'm in the thought of GWT will take care of it(as like running in Google Web App Server).

NOTE: The Application is working perfectly when i'm running the GWT modules seperately(not consumes the data from WebService) and even Spring RestTemplate Module working as good enough in consume RestService and displays the values in System.Out.println().

The core issue is in making an Interaction between GWT and 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>

Kindly provide your suggestion, how to make it work.

Thanks in Advance.

Updated: HTML File

 <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>

Entry Point Class: 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 Compiled WAR Contents:

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

解决方案

You need to separate both the modules in separate project.

You need to compile the GWT module first and then put its generated files in the main Web project and then from the controller of the web application call the .html file of the GWT project. I hope you understood this and it helps you.

这篇关于无法将GWT与Spring RestTemplate实现集成在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆