This contains your pure Java classes, entities, and business logic. It has zero external dependencies—meaning no javax.persistence annotations, no Spring Framework imports, and no third-party HTTP clients. Pillar 2: Ports (Interfaces)
Fast, pure Java unit tests validate critical business workflows. This contains your pure Java classes, entities, and
Some popular books on the topic include: This contains your pure Java classes
Here is how to structure and code a basic hexagonal service in Java. 1. Package Structure no Spring Framework imports
package com.example.ordermanagement.domain.service; import com.example.ordermanagement.domain.model.Order; import com.example.ordermanagement.ports.inbound.CreateOrderUseCase; import com.example.ordermanagement.ports.outbound.OrderRepositoryPort; import java.math.BigDecimal; public class OrderService implements CreateOrderUseCase private final OrderRepositoryPort orderRepositoryPort; public OrderService(OrderRepositoryPort orderRepositoryPort) this.orderRepositoryPort = orderRepositoryPort; @Override public Order createOrder(BigDecimal price) Order order = new Order(price); orderRepositoryPort.save(order); return order; Use code with caution. 4. Infrastructure Adapters (Spring Framework Integration)