Git Product home page Git Product logo

demo-gwt-springboot's Introduction

demo-gwt-springboot

Build Status

Build Status

Table of Contents

Demo in Heroku

Introduction

This is an example Maven project for following frameworks:

  • User Interfaces (Client):
    • GWT
    • GWTBootstrap3 for the UI
    • RestyGWT for the RESTful access to backend services
    • GIN for Dependency Injection
    • GWT Event Binder for event bus
    • GWT Mockito for UI logic test
  • Controllers and Services (Server):
    • KissMDA
    • Spring Boot for business logic implementations
    • All the standard stuffs used by Spring Framework
  • Domains (Server):
    • KissMDA
    • JPA with Hibernate

The idea of this project is to offer a simple application template for the mentioned frameworks above. If you need a more sophisticated GWT application framework you can use following frameworks:

  • ArcBees GWT-Platform: Model-View-Presenter Framework for GWT
  • JBoss Errai Framework
  • Sencha GXT

The development is based on Maven so this project can be used with Eclipse, IntelliJ or NetBeans.

Architecture

Model for Services and Domains

There are two services: UserService and PersonService and two Entities: Person and Address. Following diagram shows the structure of the services and the domains.

Service and Domain Model

Architecture

Following diagram shows the architecture of the Microservice Demo. The naming of the packages client, mock, server, shared and resource (not shown in diagram) is based on this architecture.

Architecture

Client

All the GWT (UI and REST client) classes should be located in this package. GWT transpiles all the Java sources into JavaScript sources.

Mock

The package consists of the mock implementation of the REST services at the client side (GWT). Instead of calling the real REST services it will create the mock data. For this purpose you can use the development-mock profile of Maven. It will compile the mock package and uses the mock implementation to handle the services. If you want to call the real REST services you can use development profile and GWT transpiler will remove the mock part. Please take a look the mock mechanism below.

Shared

In this package you can put any classes which will be used from both sides: client and server. It is advisable to put constants and endpoints of the RESTful services so that they point to the same address. Also DTO (Data Transfer Objects) for RESTful services should be included in this package. GWT transpiles this package into JavaScript sources.

Server

All the controller, service, repository and domain classes - based on Spring Framework - should reside in this package. This package will not be included in GWT transpiler.

Resource

All the themes for GWTBootstrap3 and general Bootstrap themes like Bootswatch should be located in this package.

You can take a look the GWT configuration file to see which packages will be included in GWT transpiler.

Mock Mechanism

The idea is to be able to develop the UI without any dependencies to the functionality of the REST API. We should be able to mock the data which come from the REST API.

Following points are important to know:

With this mechanism we can develop the UI very fast and we don't need to wait for the REST API to be implemented.

Run the WebApp for Development

Server: Start the WebApp with Spring Boot

Just run the class DemoGwtSpringbootApplication or if you are using Spring Tool Suite just run it with Spring Boot Dashboard:

STS Spring Boot Dashboard

Tips and Tricks

JRebel
  • If you are using JRebel you need to put following parameter in VM Arguments, something like:
-javaagent:C:\progjava\jrebel\jrebel.jar

or the newer version of JRebel

-agentpath:C:\progjava\jrebel\lib\jrebel64.dll

Spring Boot with JRebel parameter

  • You also have to comment out the Spring Boot Dev Tools dependency in pom.xml.
        <!-- Use this Spring Tool for restarting the app automatically -->
        <!-- Only use this if you don't use JRebel! -->
        <!--
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        -->
  • To be able to generate the rebel.xml you need to compile the project with Maven profile development.

Maven compile with Profile development

Spring Boot Dev Tools

Spring Boot Dev Tools restarts the Spring Boot App automatically if your codes have changed. You have to deactivate JRebel if you want to use this tool. This Spring Boot Dev Tools dependency should be activated:

        <!-- Use this Spring Tool for restarting the app automatically -->
        <!-- Only use this if you don't use JRebel! -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

Client: Start GWT SuperDev Mode transpiler

To be able to test quickly you can use GWT SuperDev Mode. With this tool you can just recompile the changes in GWT Java codes into JavaScript codes without restarting the process.

Follow following steps:

Starting GWT SuperDev Mode

Starting GWT SuperDev Mode Compiler from command line or within the development environment with Maven:

mvn -P development gwt:run-codeserver

To start with Mock:

mvn -P development-mock gwt:run-codeserver

At the end you can see following message:

...
[INFO] The code server is ready at http://localhost:9876/
...

Bookmark Dev Mode On

Now you can go to the given address and boomark the Dev Mode On through drag and drop into your bookmark menu.

GWT SuperDev Mode

That's it. You can just push Dev Mode On to run the transpiler directly and the WebApp will be reloaded automatically.

GWT SuperDev Mode

Browser: Call the WebApp demo-gwt-springboot from a web browser

Go to the application URL with a web browser:

http://localhost:9014/demogwt/index.html

or just

http://localhost:9014/demogwt

Heroku: Test the Webapp from Heroku

The webapp is installed at Heroku PaaS and you can test it from this address: Demo Webapp

Logging

The GWT logging is activated (see configuration file) at both sides: Client and Server.

Server: Logging at the Spring Boot Console

GWT Server Logging

Client: Logging at the Browser Console

GWT Client Logging

Debugging

Server: Debugging Spring Boot

Debugging the Spring Boot part can be achieved easily by starting the Spring Boot with Debug mode.

Client GWT: Debugging with GWT SuperDev Mode

You need to update following file: configuration file for development

    <!-- Compiler agent - we only need to compile for one web browser in development -->
    <!-- If you want to use SDBG for debugging you need to use Chrome == safari -->
    <set-property name="user.agent" value="safari" />  

For all purposes of debugging you need to use Google Chrome as your browser.

Client GWT: Debugging with Eclipse SDBG

Debugging the GWT part with Eclipse should be done by using SDBG.

Tips and Tricks for Optimizing Transpiler Speed

There are two GWT configuration files: DemoGwtDevelopment.gwt.xml and DemoGwt.gwt.xml.

  • DemoGwtDevelopment.gwt.xml: this config will be used to make the GWT compiling process faster. This only compiles for one web browser and use INFO as logging output.
  • DemoGwt.gwt.xml: this config will be used for production transpilling. This is optimized for many many production purposes.

Client GWT: Debugging with IntelliJ IDEA

For debugging gwt with IntelliJ IDEA proceed the following stets.

Prequesites

Overview

The following diagram shows the different parts of the setup:

GWT Client Logging

Step by step

Open Project in IntelliJ

Open Project in IntelliJ

After this the project is loaded and the DemoGwtSpringbootApplication will be added to the RunConfigurations automatically.

Open Project in IntelliJ

Configure Web Facet

Open in the FileMenu the Project Structure

Open Project in IntelliJ

Add add under Facets a Web Facet to the project

Open Project in IntelliJ

Add the facet to the demo-gwt-springboot module:

Open Project in IntelliJ

The path must be set to src/main/resources/public and the context must be /demogwt.

Important

Do not add the web.xml to git. Just ignore it.

Open Project in IntelliJ

Do not generate Artifacts

Open Project in IntelliJ

Close the Project Structure with Ok and reopen it. Now the Web Facet can be selected in the GWT Module.

Open Project in IntelliJ

After this you should select only the GWT Module DemoGwtDevelopment

Open Project in IntelliJ

GWT Configuration

Add a new Run Configuration

Open Project in IntelliJ

And a GWT Configuration:

Open Project in IntelliJ

After this you start the "Spring Boot Project" first and after this the "GWT-Project" in Debug mode.

Codeserver

Now you have to repeat the steps to configure the code server (see above).

Running the debugger with the IDE Support Plugin

You should see the alert that the »JetBrains IDE Support« is running in debug mode.

If you have any trouble connecting the browser with the idea, please check the ports of the browser plugin and Intellij.

Right click on the Life Edit extension and choose Options:

GWT Client Logging

The default port is 63342.

GWT Client Logging

And check if the port in the Intellij IDEA debugger is configured on the same port.

GWT Client Logging

Unit and Integration Testing

Server: Spring Test

Examples of unit test with POJO and Mockito:

Examples of integration test with Spring and in memory database:

Client: GWT Mockito

We use GWT Mockito for writing the GWT user interface unit test. Following is an example of GWT Mockito unit test:

demo-gwt-springboot's People

Contributors

idueppe avatar lofidewanto avatar oleksandrprognimak avatar tripti87 avatar

Stargazers

 avatar  avatar  avatar  avatar

Forkers

appletv850 oucem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.