Back & ArchitectureTechnologies

Microservices Architecture (MSA)

Today we are going to talk about Domain Driven Design (DDD) and microservices with Spring and Java +8. This article is intended as a beginner’s kit where you will find:

  • DDD View
  • Spring and springboot with main examples and annotations
  • Spring core on main examples and annotations
  • Spring data, patterns and some utilities:
    • jpa
    • lombok
    • mapstruct
    • jackson
    • jbxb

To facilitate the follow-up of this entry, we have prepared a PDF file with the contents:

Technological Environment

Having said that, let’s see the tools and technologies that will be used for the Product’s environment:

Development tools

ToolURLVersionInfo
Spring Tool
Suite
https://spring.io/toolsSpring Tools 4 for EclipseSpring Tool Suite is an Eclipse-based development environment that is modified to develop Spring applications.
Mavenhttps://maven.apache.org/Maven 3.5 or higherApache Maven is a tool for managing and understanding a software project.
Git / Gitlabhttps://about.gitlab.com/Gitlab is a Git-based web service for version control and collaborative development.
Sourcetreehttps://www.sourcetreeapp.com/Sourcetree 3 or higherSourcetree is a Git-based GUI that provides a visual representation of your repositories. Sourcetree is a free Git client for Windows and Mac.
Junithttps://junit.org/junit5/Junit 5 or higherJUnit is an open-source framework for the purpose of writing and running tests in the Java programming language (Implemented with Mockito 2.X https://site.mockito.org/). Maven Plugins: JaCoCo Maven plug-in provides the JaCoCo runtime agent to your tests and allows the creation of basic reports.
Sonarqubehttps://www.sonarqube.org/Sonarqube 7 or higherSonarqube is an open-source platform developed by SonarSource for continuous code quality inspection to perform automatic reviews with static code analysis to detect bugs, code smells, and security vulnerabilities.
Jenkinshttps://jenkins.io/Jenkins 2 or higherJenkins is an open-source automated server written in Java. Jenkins helps automate the non-human part of the software development process, with continuous integration and making the technical aspects of continuous delivery easier.
Nexushttps://www.sonatype.com/nexus-repository-sonatypeNexus 3 or higherNexus is a repository manager. It allows you to collect and manage your dependencies so you don’t have to constantly shuffle through a collection of JARs. It makes it easier to distribute your software. Internally, you configure your build to publish artifacts to the Nexus and then make them available to other developers.

Environment specifications

SpecificationURLVersionInfo
OpenJDKhttps://adoptopenjdk.net/Openjdk 8.XOpenJDK is the free version of the Java development platform under the object-oriented language concept.
Spring Frameworkhttps://spring.io/Spring 5.XSpring Framework is an application framework and inversion of control wrapper for the Java platform. The core features of the framework can be used by any Java application, but there are extensions for building web applications on top of the Java EE (Enterprise Edition) platform.
Spring-Boothttps://spring.io/projects/spring-bootSpring-Boot 2.XSpring Boot was designed to simplify the bootstrapping and development of new Spring applications. The framework takes a dogmatic approach to configuration, freeing developers from the need to define boilerplate configuration.
Swaggerhttps://swagger.io/Swagger 2.X or higherSwagger is an open-source software framework, backed by a large ecosystem of tools, that helps developers design, build, document, and consume RESTful web services.
Tomcathttp://tomcat.apache.org/Tomcat 9.XApache Tomcat, commonly referred to as Tomcat Server, is an open-source Java Servlet Container developed by the Apache Software Foundation (ASF). Look at Tomcat embedded in Spring Boot.
Dockerhttps://www.docker.com/Docker 18.XDocker is a tool designed to make it easy to build, deploy, and run applications using containers. Containers allow a developer to package an application with all the parts it will needs, such as its libraries and other dependencies, and ship everything as a single package.
Kuberneteshttps://kubernetes.io/Kubernetes 1.XKubernetes (K8s) is an open-source system to automatically deploy, scale, and manage containerized applications.
Rancherhttps://rancher.com/Rancher 2.XRancher combines everything an organization needs to run containers in production and to centrally manage multiple Kubernetes clusters. Request a demo today!
Azurehttps://azure.microsoft.com/es-es/Microsoft Azure is a cloud computing service created by Microsoft to build, test, deploy, and manage applications and services through Microsoft data centers.
Onesait
Platform
https://onesaitplatform.atlassian.net/XOnesait Platform provides flexibility for our clients to build their own solutions in a robust and agile way, using open-source technologies, a flexible architecture, and an innovative approach.

Microservices in Spring

Currently Spring is an open source framework that facilitates the development of Java JEE & JSE applications. It is made up of multiple modules/projects covering all layers of the application, with dozens of developers and thousands of downloads per day. It provides a container in charge of managing the life cycle of objects (beans) so that developers can focus on business logic. It allows integration with different frameworks. Due to this capacity for modularity and development in different environments, it is optimal for the implementation of microservices.

Features

These microservices are characterized by being:

  • Lightweight: the impact of integrating Spring is minimal.
  • Non-intrusive: in general, the objects that are programmed do not have dependencies on Spring-specific classes.
  • Resilient: although Spring provides functionality to handle the different layers of the application (view, business logic, data access), it is not necessary to use it for everything. It offers the possibility of using it in the layer or layers that we want.
  • Cross-platform: written in Java, runs on JVM.

Modules to use

The main modules that are necessary to develop microservices in Spring are Spring Framework, Spring Data, Spring Boot and Spring Security:

  • Spring Framework: Provides a comprehensive programming and configuration model for modern Java-based enterprise applications, on any type of deployment platform. A key element of Spring is the application-level infrastructure support: it focuses on communications between the storage, system, and network layers of enterprise applications so that teams can focus on business logic at the application level, without unnecessary links to specific deployment environments.
  • Spring Boot: it is a tool that was born with the purpose of simplifying the development of applications based on the Spring Core framework: the developer only focuses on the development of the solution, completely forgetting about the complex configuration that Spring Core currently has for be able to function, especially by providing a quick start with less coding.
  • Spring Data: is a SpringSource project (subprojects) whose purpose is to unify and facilitate access to different types of persistence technologies, both relational and NoSQL-type databases. It comes to cover the necessary support for different NoSQL database technologies, integrating them with traditional data access technologies, thus simplifying the work when creating specific implementations.
    Normally it uses a repository class that acts as a mediator between the application domain and the data that gives it persistence. The repetitive task of creating the concrete DAO implementations for the entities is simplified, because only one interface is needed, and provided.
  • Spring Security: this module provides Spring with a number of applicable security services for systems based on the J2EE-based architecture. The security processes are mainly intended to verify the identity of the user through authentication and the permissions associated with it through authorization. The authorization is dependent on the authentication, since it occurs after its process.

Summary of frequent IoC annotations

  • Self-discovery: categorize each one of the components, associating them with a specific responsibility: @Scope, @Component, @Repository, @Service, @Controller.
  • Customization: @Configuration, @Bean.
  • Injection: by default the injection is mandatory. It can be marked as optional in which case, should the Bean be not found, a null will be injected: @Autowire (@Inject), @Qualifier (@Named), @Value, @PropertySource, @Required, @ Resource.
  • JPA: @Entity, @Table (applies to a class), @Id, @column, @Transient (applies to Java properties).
  • Others: @PostConstruct, @PreDestroy.

More information

You can find more information about it on the Spring website, as well as on the Lombok plugin website.

✍🏻 Author(s)

Leave a Reply

Your email address will not be published. Required fields are marked *