hirannor / springboot-hexagonal-ddd

Spring-Boot application based on hexagonal architecture and DDD

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring-Boot - Ports-And-Adapters / Hexagonal Architecture with DDD

Overview

An example of a Spring-Boot application, which based on the port and adapters/hexagonal architecture and DDD.

Build Status License
Build Status License: MIT

Prerequisites for development

Implementing new adapter

The whole component scan for the adapter package is excluded in the application, so the unnecessary adapter beans won't be loaded into the application context, just the configured ones. Each adapter defines her own spring configuration class, which is imported via the @Import annotation (on top of the application's main class) but getting only component scanned if the condition fulfills for it via @ConditionalOnProperty annotation.

Based on the below example if you define "spring-data-jpa" value as a persistence adapter in the application-[profile].yml, then it will activate the corresponding Configuration class, which is going to component scan the underlying packages for spring beans.

Example

@Configuration
@EnableJpaRepositories
@ComponentScan
@ConditionalOnProperty(
        value = "adapter.persistence",
        havingValue = "spring-data-jpa"
)
public class JpaPersistenceConfiguration {

}

application-[profile].yml

adapter:
  authentication: basic
  persistence: spring-data-jpa
  messaging: spring-event-bus
  web: rest

Build and test with Maven

mvn clean verify

**Building and verifying the application requires a running docker, since some tests are using Testcontainers library!

Test catalog and Maven lifecycle bindings

Test catalog type Maven lifecycle
Unit test test
Component test test
ArchUnit test test
Integration test verify
Functional test verify

API Documentation

You can access the API documentation locally at the following URL:

http://localhost:8080/swagger-ui/index.html

Preview