This is an example Maven project for following frameworks:
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:
The development is based on Maven so this project can be used with Eclipse, IntelliJ or NetBeans.
There are two services: UserService and PersonService and two Entities: Person and Address. Following diagram shows the structure of the services and the domains.
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.
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.
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.
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.
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:
RestServiceinterface. Example: UserClient.java.
development-mock. In this profile we call a special GWT module file which will be used to transpile the Java code:
src pathto transpile the
mockpackage. Also we define what EntryPoint
DemoGwtMockEntryPointclass we would like to use in this profile:
With this mechanism we can develop the UI very fast and we don't need to wait for the REST API to be implemented.
Just run the class DemoGwtSpringbootApplication or if you are using Spring Tool Suite just run it with Spring Boot Dashboard:
or the newer version of JRebel
<!-- 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> -->
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>
Follow following steps:
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/ ...
Now you can go to the given address and boomark the Dev Mode On through drag and drop into your bookmark menu.
That's it. You can just push Dev Mode On to run the transpiler directly and the WebApp will be reloaded automatically.
Go to the application URL with a web browser:
The webapp is installed at Heroku PaaS and you can test it from this address: Demo Webapp
The GWT logging is activated (see configuration file) at both sides: Client and Server.
Debugging the Spring Boot part can be achieved easily by starting the Spring Boot with Debug 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.
Debugging the GWT part with Eclipse should be done by using SDBG.
Tips and Tricks for Optimizing Transpiler Speed
For debugging gwt with IntelliJ IDEA proceed the following stets.
The following diagram shows the different parts of the setup:
After this the project is loaded and the
DemoGwtSpringbootApplication will be added to the
Open in the
Add add under
Web Facet to the project
Add the facet to the
The path must be set to
src/main/resources/public and the context must be
Do not add the web.xml to git. Just ignore it.
Project Structure with
Ok and reopen it. Now the
Web Facet can be selected in the GWT Module.
After this you should select only the GWT Module
Add a new Run Configuration
And a GWT Configuration:
After this you start the "Spring Boot Project" first and after this the "GWT-Project" in Debug mode.
Now you have to repeat the steps to configure the code server (see above).
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:
The default port is
And check if the port in the Intellij IDEA debugger is configured on the same port.
Examples of unit test with POJO and Mockito:
Examples of integration test with Spring and in memory database:
We use GWT Mockito for writing the GWT user interface unit test. Following is an example of GWT Mockito unit test: