Java

A Pragmatic Guide to Spring Boot Architecture: Choosing Between Three-Layer and Clean Architecture

Software architecture is the foundational blueprint that determines the long-term success of an application. For developers working with Spring Boot, architectural choices have a direct impact on maintainability, scalability, and overall development productivity. A poorly chosen structure can result in a codebase that is hard to test, expensive to modify, and slow to evolve. Among the available patterns, Three-Layer Architecture and Clean Architecture are two of the most frequently used approaches. The former emphasizes simplicity and delivery speed, while the latter focuses on domain-centric design and long-term flexibility. This guide provides a clear, comparative analysis of both architectures, complete with practical examples, to help teams make informed decisions based on their project’s goals and constraints.

Continue Reading

Hexagonal Architecture (Ports & Adapters) explanation with Spring Boot examples:

Hexagonal Architecture

Hexagonal Architecture (HA), also known as Ports and Adapters Architecture, is a foundational and influential software design pattern, first introduced by Alistair Cockburn in 2005.

The term “Hexagonal Architecture” comes from a visual convention: the application component is drawn as a hexagon, not to imply it must have six boundaries or ports, but to leave enough space to represent the different interfaces connecting the component to the outside world. As Cockburn stated in his 2005 article:

The hexagon is not a hexagon because the number six is important, but rather to allow the people doing the drawing to have room to insert ports and adapters as they need, not being constrained by a one-dimensional layered drawing.

This insight is crucial—it reminds us to stop focusing on the shape and instead focus on the core concept: defining the application’s API via ports and connecting it to the outside world with interchangeable adapters. This shift from diagram to intent is the first step toward architectural maturity.

Ports & Adapters (Hexagonal Architecture) explicitly defines two layers: the inside (application core) and the outside (everything else), and requires clear definition of ports for interaction.

(Clean Architecture builds on this by further splitting the application core into more granular layers such as Use Cases, Entities, and Domain Services, but is less prescriptive about the “port” metaphor for the outer boundary.)

Continue Reading

Design Multiple Environment Configuration on Spring Boot

A Complete Guide to Multi-Environment Configuration in Spring Boot

In real-world development and deployment, a single project often needs to run in multiple environments (e.g., local, dev, staging, production).
Spring Boot provides a powerful mechanism for environment-based configuration, allowing us to automatically load different settings based on runtime environment variables.

This article walks through how to design a clean and maintainable multi-environment configuration structure step by step.

Continue Reading

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

Implementing an OAuth2 Authorization Server with Spring Boot and MyBatis

In modern application development, secure authentication and authorization are crucial components. This article demonstrates how to implement a Login Service using:

  • Spring Boot (REST API, MVC pattern)
  • Spring Security + Authorization Server (OAuth2.1)
  • MyBatis (database persistence)
  • MySQL (user and token storage)

The system acts as:

  1. OAuth2 Authorization Server (issue JWT access tokens & refresh tokens).
  2. OAuth2 Client (support login with Google in the future).
  3. Resource Server validator (other services can validate tokens issued here).

Continue Reading

當Java 向 Google 索賠侵權成功,是不是一種危機

Google的Android在一開始就以Java語言進行開發,這項決定,卻導致長達一年的侵權官司。

由甲骨文起訴Google,原因是Android系統侵犯了甲骨文在Java平台核心的幾項智慧財產權。並且,就在29日晚上,確定Google無法再繼續上訴,必須支付授權費,並禁止使用甲骨文的專利技術。

圖片來源: http://androidcommunity.com/

Continue Reading