Spring Boot

In Programming Sharing. More on Medium.

As a java developer, I guest that you heard about the connection pool and might apply it to your system. Therefore in this article, we will learn how to configure C3P0 which is the most popular connection-pool library for java developers.

What is the C3P0 connection pool?

If you are a fan of Start War you might think C3P0 is this guy.

Photo by Lyman Gerona on Unsplash

At my first time hearing about the connection pool and saw C3P0, I have made a mistake about the ZERO and O letter. I did not know and googling c3po and google show me this guy and I was confused. …

In this article, we learn how to use Transactional annotation in a spring application to guarantee the consistency of data.

Why we need transactions?

Let start with an example of saving order information. In many cases to store order information, we will have two tables let call Order and OrderLine. In consequently the system must save data for the order first then sort info of order line items. Now have to think about the case we save Order data successfully but the OrderLine failed. For this case, we have to rollback the order info to be not saved in the database to guarantee the consistency of the order information. In such problems, we have to use transactions.

working with transaction in applications
working with transaction in applications
common flow when working with transaction

The benefits of using Transactional annotation

Reduce boilplate code

In java or other languages, the developer…

Let’s learn how to update the document with MongoTemplate with an explanation of how it works.

Follow part one of the CRUD document using MongoTemplate series which shares about inserting documents, in this article, we will learn how to update documents by using MongoTemplate.

Update behavior

MongoTemplate provides a save method that allows updating documents. The diagram below shows how the save method work in basic.

How the mongotemplate save method works
How the mongotemplate save method works
  • At first, if the _id value was not provided the MongoDB will process the saving document as inserting a new document.
  • If the _id provided, MongoDB server will scan the collection and tries to a matching document with provided _id value. If a document matching the provided _id found, it will be…

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.

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…

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 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

This article shows you how to configure Caffeine Cache in a Spring Boot application and also provides some important notes.

Spring Cache Abstraction allows us to quickly make the application become cacheable. But it does not provide any real cache storage, it just provides cache features as ConcurrentMap which provided by the JDK.

Now, in this article, we are going to configure Caffeine Cache as cache storage for the Spring Application. Before jumping to the coding section, let’s have a quick intro about Caffeine Cache and Spring Cache Abstraction.

Caffeine Cache and Spring Boot
Caffeine Cache and Spring Boot
Photo by Alex Jones on Unsplash

Introduction to Caffeine Cache

Caffein is a high-performance Java 8 based caching library providing a near-optimal hit rate.

Caffeine Cache is similar to JDK ConcurrentMap but is not quite the same. A JDK ConcurrentMap persists…

Learn how to integrate Hazelcast IMDG into a Spring Boot application.

In another article, I have introduced Spring Cache Abstraction. Following that article, In this article, I am going to show you how to configure Hazelcast in the Spring Boot application.

Before getting started with code implement, we should go through the basics of what is Hazelcast and Spring Cache Abstraction.

What is Hazelcast IMDG?

Hazelcast IMDG is an open-source distributed in-memory object store supporting a wide variety of data structures.

You can use Hazelcast IMDG to store your data in RAM, spread and replicate it across your cluster of machines, and perform computations on it. …

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?

Ehcache is an open-source, standards-based cache that boosts performance, offloads your database, and simplifies scalability. It’s the most widely-used Java-based…

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…

Programming Sharing

We write about programming. We share about programming.

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