An article showing how to configure Ehcache in Spring Boot application. It’s covered for both Ehcache 2 and Ehcache 3.

In another article, I have introduced to Spring Cache Abstraction. Following that article, In this article, I am going to show you how to configure Ehcache in the Spring Boot application(similarly, you can do for non-spring application by adding more dependencies).

configure ehcache in spring boot
configure ehcache in spring boot

Before jumping to the code demo section, I want to have a quick introduction to Ehcache, spring-boot-autoconfigure module, and spring-context-support module. Going through these pieces should be great to understand more what I do in the code demo section.

What is Ehcache?


Caching is well-known as the most approach to increase application performance. Caching helps reduce the cost of CPU expensive operations such as Fibonacci calculation. Besides CPU expensive operations, caching also helps reduce IO expensive operations such as reading files from disk. Unfortunately, efficiently applying cache into the application is no simple task.

Providing an abstraction caching layer.

Spring Framework provides cache implementation in the spring-context module with a simple cache store that is ConcurrentHashMapif no cache library found on the classpath. Otherwise, in case we have included supported cache libraries in the classpath,

With the spring cache, It has many built-in annotations to manage cache…


Learn how to configure and connect a spring boot application to MongoDB.

In recent decade Mongodb rises to become of the most database used in the software industry. This database stands on top of document databases it provides the scalability and flexibility that you want with the querying and indexing that you need. Therefore, I would like to share how we can connect a spring application to MongoDB and execute basic accessing data operations.

Image for post
Image for post
Photo by Yomex Owo on Unsplash

How does spring boot support integrating MongoDB?

Before jumping to code, I would like to introduce how does spring support MongoDB in basic.

Spring boot supports MongoDB integration through the spring-boot-starter-data-mongodb module which already included spring-boot-starter, mongodb-driver-sync and spring-data-mongodb modules. Each module has a different…


Learn how to integrate HikariCP in the Spring Boot application.

In order to increase the performance while accessing data from a database, we must consider applying the connection-pool. You can search to know how does it help to increase the performance. I already wrote an article about this here:

In this article, I would like to share how we use the HikariCP library in a Spring Boot application.

Why HikariCP?

HikariCP is a lightweight connection-pool library. This library is also known as the fastest connection pool library. “Fast, simple, reliable, lightweight” are four words used to describe it. At the time I’m writing this article it has more than 63.3k …


Many systems require auditing and tracking the change in the persistence layer. It is really helpful to investigate problems related to the data. Data auditing typically answers these questions: when was it created, who was create the record, when was it created, who modified the record last and when was it modified last. In this article, we will learn how to implement auditing features.

How Spring Data JPA support auditing

By now, Spring provides four annotations in the spring-data-commons module for auditing features. They are:

  • @CreatedByrepresents the principal that created the entity containing the field.
  • @CreatedDate represents the date the entity containing the field was created.


This article shows you how to do paging and sorting data with Spring Data JPA.

Image for post
Image for post
Photo by Edu Grande on Unsplash

Any good developers know that fetching large data then render the view or response within a single request is a bad idea for a high-performance application. So in this article, I would like to share with you how to do paging and sort data with Spring Data JPA. This article gives you a solution to handle the most popular feature in most applications such as displaying products in the e-commerce system.

How Spring JPA supports paging and sorting data

Before going to the demo, I would like to share with you how Spring Data JPA supports developers for doing paging and sorting.


Spring Data JPA already provides many solutions that allow us querying data easier such as Query Method, Query Method, or four repository interface(JpaRepository, PagingAndSortingRepository, CrudRepository, Repository). These features are powerful, which help me a lot when building an application with Spring Data JPA. But a lot of time we still need to custom query or method to meet expectations or requirements.

Custom Repository in Spring Data JPA
Custom Repository in Spring Data JPA

The class design diagram above indicates how we can create a custom repository in Spring Data JPA. We just need to let EmployeeRepository implement the custom interface and define the implementation for the customized repository. …


Version Control is very important to make sure any change in the source code should be recorded and allow us to recall a specific version later. Imagine we edit some lines of code then deploy it without full-test then the error occurs due to the changes, unfortunately, we forgot to make a backup of the old code. Now how do we can revert to the previous version? In order to avoid these problems, we need a version control system to record and keep track of all changes in our code.

A version control system allows us to revert a selected…


This article shows you how to configure the H2 database within a Spring Boot application.

What is H2 database?

H2 database is an open-source in-memory database that can be easily embedded into Java application. H2 database provides a list of features such as Pure Java, memory mode, encrypted database, ODBC driver even full-text search. Its size approx around 2MB.

H2 database also provides a browser-based Console application to manage data.

h2 database browser-based Console application
h2 database browser-based Console application
h2 browser-based console application


In this article, we will learn about message term in Spring Integration

Image for post
Image for post
Photo by Anne Nygård on Unsplash

In order to loose coupling between components in a system, we typically apply the messaging system to achieve that aim. That requires a solid understanding of what is a message and some type of message for effective use for specific scenarios. So in this article, I would like to share the definition of the message, the structure of a message, and common types of messages in a messaging system.

What is a message in a messaging system?

As the spring integration reference document defined that “In Spring Integration, a message is a generic wrapper for any…

Thanh Tran

Software Engineer at Terralogic. Blogger and Amateur Investor

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store