Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clean Architecture with Spring (Spring I/O 2019)

Clean Architecture with Spring (Spring I/O 2019)

Buzzwords like “Clean Architecture” and “Hexagonal Architecture” have been around for quite some time now. But have you actually seen an application built with one of these paradigms? How do we actually implement such an architecture in a way that the software we create stays flexible and maintainable?

This talk presents the concepts and reasoning behind the buzzwords “Clean Architecture” and “Hexagonal Architecture” and translates them into actual code. Going through an example web application based on Java and Spring, we’ll discuss the full stack ranging from the web layer to the persistence layer. How should we structure our application? Where does the input validation code belong? How do I access my domain logic? How can I let my bounded contexts communicate cleanly? And how does Spring help with all of this? These questions and more will be answered.

Tom Hombergs

May 17, 2019
Tweet

More Decks by Tom Hombergs

Other Decks in Technology

Transcript

  1. The Ultimate Goal of Architecture The goal of software architecture

    is to minimize the lifetime cost of the software
  2. SOLID Principles S O L I D Single Responsibility Principle

    Open-Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle
  3. Dependency Inversion Principle SOLID Principles S O L I D

    Single Responsibility Principle Open-Closed Principle Liskov Substitution Principle Interface Segregation Principle
  4. Dependency Inversion Principle We can choose the direction of any

    code dependency* * As long as we have control over the code
  5. Single Responsibility Principle Dependency Inversion Principle SOLID Principles S O

    L I D Open-Closed Principle Liskov Substitution Principle Interface Segregation Principle
  6. Single Responsibility Principle A module* should have only one reason

    to change * Read: class, package, component, architecture element, software entity, …
  7. Spring & Clean Architecture Spring doesn't care about which architecture

    we're implementing Spring is easily held at arm's length Spring helps to test isolated parts of our architecture
  8. Enforcing the Architecture - ArchUnit @Test void validateRegistrationContextArchitecture() { HexagonalArchitecture

    .boundedContext("io.reflectoring.copyeditor.registration") .withDomain("domain") .withAdapters("adapter") .incoming("in.web") .outgoing("out.persistence") .and() .withApplicationLayer("application") .services("book") .services("invitation") .incomingPorts("port.in") .outgoingPorts("port.out") .and() .withConfiguration("configuration") .check(allClasses()); }
  9. Enforcing the Architecture - Java Module System Yes, it will

    probably work … … but I'm used to having 5 years of time to learn each new Java version.