Monday, November 12, 2018

Spring Boot - Modularizing project into modules and re-use

While working with microservices, there will be many small modules in your systems, they calls each others, for me it would be great if we can share at least the data transfer classes. It will save time on development

Here is the structure of my example

rest-module-example

In the example, I created a rest-module-example module, it is the main module which separated into 2 modules ( dto.jar and app.jar )

The rest-module-consumer-example will include the dto.jar ( by Maven or Gradle ) , so It will be easy to consume the REST API

You can find details implementation in the repos below:

rest-module-example: https://github.com/vanduc1102/spring-boot-examples/tree/master/module-rest-example

rest-module-consumer-example: https://github.com/vanduc1102/spring-boot-examples/tree/master/module-rest-consumer-example

Monday, November 5, 2018

Spring Boot override Bootstrap properties

1. Bootstrap properties file is inside the packaged jar


This is not a useful case to manage the bootstrap properties or application properties, the reason is you have to rebuild your application again if made any change to the properties

You should have properties file name following the format bootstrap-{profile}.yml ( or .properties variants)


2. Bootstrap properties is outside of the packaged jar.


I prefer this case to manage properties, we don’t need to rebuild the application again if we made change to properties also we can manage our properties better with VCS like git.

Let assume that we have a configuration file outside of packaged jar.

In order to load the file, we need to change the bootstrap properties location by override the spring.cloud.bootstrap.location attribute.



With this approach we can easily override the bootstrap properties.

Wednesday, October 24, 2018

Spring Boot Sleuth and ZipKin

This post is my implementation of the post here: https://reflectoring.io/tracing-with-spring-cloud-sleuth/


Although the post already included the source code, but it is still pretty hard for me to start


So I created this post to help me to remember how to make Slueth and Zipkin work.


Spring Cloud Sleuth


will add traceId and spanId to logger
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<version>${spring-cloud.version}</version>
</dependency>

Analyze Traces with ZipKin


Logger collector and analytics
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>${spring-cloud.version}</version>
</dependency>

spring.sleuth.sampler.percentage=1.0


Is percentage of sampler, the default value is 0.1 ( 10%) that means you only take 10% of request to sampler


Change to 1.0 ( 100% ) to sample all of request.


Repo URL: https://github.com/vanduc1102/tutorials/tree/master/spring-sleuth

 

Monday, October 8, 2018

Spring Boot 2 - REST template project

Recently, I have a chance to work with Spring Boot, it was pretty hard for me to create Spring project without template that is ready for development. So I created a template to help me save time for next projects.

What are included in this boilerplate:

Github Repo: https://github.com/vanduc1102/spring-boot-examples/tree/master/spring-boot-2-rest-service-basic

Sunday, August 5, 2018

Install Eclipse Window

Before start install Eclipse, you should check if your PC had installed Java(JDK) here : https://aduckdev.wordpress.com/2018/08/04/how-to-install-jdk-and-setup-java_home-in-windows-10/


Download Eclipse

Open: http://www.eclipse.org/downloads/download.php




Open the downloaded file to start installation:

Screenshot_1



Choose IDE for Java Developer:

Screenshot_2

Choose a folder for installation, we will use default value here.

Screenshot_3

Click Next to install, after the installation finished, click Launch to launch Eclipse

launch

Choose workspace folder. You can use the default also.

Screenshot_4

And here is your Eclipse.

Screenshot_5



How to setup ANDROID_HOME

In order to setup ANDROID_HOME, you need to have Android SDK installed on your PC

Checkout this link: https://developer.android.com/studio/ you can find both Android Studio and Android SDK

Screenshot_5.png

What is Android SDK: it is a bundled of command line tools help you to develop an Android application, it is shipped inside Android Studio

This tutorial show you how to setup ANDROID_HOME variable after you installed Android Studio

1.To find location of Android SDK on your PC. Open Android Studio


Open File --> Settings, type SDK and you will see the location of SDK on your PC, here is: C:\Users\DucNGUYEN\AppData\Local\Android\Sdk 

Screenshot_4.png

2. Setup ANDROID_HOME environment


Open Advanced System Settings: hit Window key and type advanced systemScreenshot_1

Choose Environment variable

Screenshot_3

Add the new variable ADROID_HOME:

Screenshot_6.png
Click OK to save variable and exit the Advanced System Settings.

3. Check the variable installed


Open new Command Prompt window and type echo %ANDROID_HOME% to check

Screenshot_7

DONE

Install NodeJS on Windows

Step 1. Download NodeJS


Open: https://nodejs.org/en/download/

Screenshot_18
Download 64bit version

Step 2. Install the downloaded file


Install downloaded msi file

Screenshot_1 Right click on download msi file[/caption]

Screenshot_2
Click on Next, Next to install as normal application

Screenshot_3
Installation successfully

Step 3. Verify the installation


Screenshot_4
Open Command Prompt to check.

Congratulations