could not integrate GWT with Spring RestTemplate i

2019-09-03 04:48发布

问题:

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

回答1:

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.