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.