Spring Boot

A Guide to Multi-Module Projects in Spring Boot

A Multi-module Maven Project is a software architecture pattern that allows developers to split a large project into multiple interconnected sub-modules, all managed by a single parent project.

This parent-child Maven structure aligns well with microservices architecture. For example, a parent project can contain gateway and auth-service sub-modules. After packaging, these two modules can be deployed and maintained separately.

It’s important to note that this parent-child relationship is for build management, not a functional hierarchy. The parent POM centralizes dependency management, but it doesn’t mean gateway necessarily depends on auth-service.

Programmatic Dependencies: If the gateway module needs to use classes from auth-service, you would add a dependency in its pom.xml. However, in a typical microservices setup, gateway and auth-service communicate via HTTP APIs or OAuth tokens, eliminating the need for a direct JAR dependency.

A typical multi-module project structure in Maven looks like this:

workspace/
 ├─ pom.xml           <-- Parent POM, defines dependencyManagement, pluginManagement, versions
 ├─ gateway/          <-- Child module
 │   └─ pom.xml
 └─ auth-service/     <-- Child module
     └─ pom.xml

Continue Reading

Robust SpringBoot Deployments: Health Checks, Versioning, and Makefile Automation

In a microservices architecture, service health checks and a reliable Linux deployment process are key to operational stability. This article will share how to build a health check interface in Spring Boot, combined with version management, and how to deploy and manage a Spring Boot JAR in a Linux environment to achieve automated execution and monitoring.

This article will explain how to build a health check interface in Spring Boot, manage versions using Maven BuildProperties, and use a Makefile for streamlined operations, automating the process from development to deployment. Finally, it will cover running the JAR on Linux and managing it with Supervisor.

Continue Reading

A Professional Guide to MyBatis: From Basics to Advanced Techniques

What is MyBatis?

MyBatis is a first-class persistence framework that provides an alternative to traditional Object-Relational Mapping (ORM) solutions like Hibernate or JPA. Often referred to as a “SQL Mapper,” MyBatis distinguishes itself by embracing SQL. Instead of abstracting SQL away, it puts developers in full control, mapping SQL statements to Java methods.

The core philosophy of MyBatis is to decouple SQL from application logic while allowing you to leverage the full power of your database. It achieves this by mapping:

  • Result Mapping: The results of a SQL query to Java objects.
  • Parameter Mapping: Java objects and parameters to SQL statement placeholders.

This approach makes MyBatis an excellent choice for projects that require precise control over SQL, such as financial systems, high-performance transaction platforms, or applications with complex, performance-sensitive queries.

In a Spring Boot ecosystem, MyBatis can be integrated primarily in two ways:

  1. Mapper Interface + XML (Recommended): Offers maximum flexibility for writing and maintaining complex SQL.
  2. Mapper Interface + Annotations: Suitable for simple queries and smaller projects.

Continue Reading