Blog
Collection of curated blog posts from me.
Mastering Error Handling in Spring Boot with ProblemDetails
Image by author Introduction Hello everyone! In this article I will try to cover a game — changer for API error handling in Spring Boot — the ProblemDetails RFC. If you spent a long time wrestling with inconsistent error responses or scratching your head over how to structure your API’s error message, you’re in for a treat. What is the deal with ProblemDetails? Spring Boot + ProblemDetails First of all the ProblemDetails is not just another Spring Boot feature — it is an IETF standard (RFC 9457) that defines a “problem detail” as a way to carry machine-readable details error in a HTTP response.
September 26, 2024
Automate your business processes with Temporal.io and Java
Introduction Today the world is a fast-paced business environment, and automating processes is crucial for staying competitive. Temporal.io, a powerful open — source platform, simplifies the development, of scalable workflow automation. Temporal.io enables developers to create efficient, resilient business process automation not only with Java but with a wide — range of different programming languages. In this article, we will explore how to leverage Temporal.io and Java to streamline your operations.
September 24, 2024
Mastering JUnit 5 - Advanced Techniques for Efficient and Powerful testing
Meme about unit tests Hello everyone in this article we will dive into note-worthy JUnit 5 annotations which help you to write extensive unit tests. Before starting to start writing unit tests we have to add required dependencies to our pom.xml or build.gradle. pom.xml<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>me.vrnsky</groupId> <artifactId>mastering-junit</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-params</artifactId> <version>5.11.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.11.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.11.0</version> <scope>test</scope> </dependency> </dependencies> </project> Parametrized test This article will follow test — driven development approach, so first, we will write a unit test. Most of the examples of test units contain examples of testing simple calculators, but for this example, we will develop a String utility class.
September 24, 2024
Advanced Java Garbage Collection — G1 and ZGC
Garbage collector Hello everyone! In this article, we discuss advanced Java Garbage Collection: G1 and ZGC. Introduction Both garbage collectors are designed to optimize memory management in large-scale applications by improving the efficiency of memory allocation, deallocation, and garbage collection. Both G1 and ZGC are designed to reduce pauses while performing the garbage collection cycle and improve overall system performance. G1 or Garbage First G1 is a fully incremental garbage collector that divides memory into multiple regions. The G1 garbage collector is concurrent. The division approach brings more efficient usage of memory by dynamically allocating objects in different regions based on their usage patterns.
August 15, 2024
Spring Boot & Infisical - Managing your sensitive configuration
Hello everyone! In this article, I’ll show you how to employ Infisical in your Spring Boot application. But last year, HashiCorp changed Terraform’s license to non-open source. This could also happen to Vault, or not. The second reason why I chose Infisical for this article is because IBM acquired Terraform this year. Introduction Like the HashiCorp Vault, Infisical is a secret management platform. Let’s start by starting up the Infisical instance locally with the docker-compose file provided by the documentation. First, we need to download it with the following command.
May 30, 2024
Spring Boot - How to build layered jar
In this article, I will show you how you can build a simple CRUD application and create a layered jar. The inventory service manages inventory, such as left stocks, i.e., some drinks, merch, or something else that can be stored in the warehouse. Reasons for choosing layered jar: If you have an extensive application with different dependencies If you need flexibility in layer updates Reasons for choosing Uber Jar: If you have a simple application with a relatively small number of dependencies If you need simplicity in the deployment process DockerfileFROM eclipse-temurin:17 as JAR_EXTRACT WORKDIR /app ARG JAR_FILE=*.jar COPY ./target/${JAR_FILE} ./app.jar RUN java -Djarmode=layertools -jar ./app.jar extract FROM eclipse-temurin:17 WORKDIR /application COPY --from=JAR_EXTRACT /app/dependencies ./ COPY --from=JAR_EXTRACT /app/spring-boot-loader ./ COPY --from=JAR_EXTRACT /app/snapshot-dependencies ./ COPY --from=JAR_EXTRACT /app/application ./ ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"] EXPOSE 8080 Access full article MediumFollow & read SubstackSubscribe & read
January 6, 2024
Spring Boot and gRPC - Boost your service communication
Introduction In this article, I will describe gRPC and how you can employ it in your project. The motivation creation of gRPC The motivation behind creating gRPC was that developers and businesses require faster and more efficient solutions. The existing technologies utilize HTTP 1/1.1. The Spring Boot supports Undertow, but Tomcat requires some additional changes. It is why creators employed HTTP 2 in gRPC. This article will create another CRUD service to manage restaurant reservations.
January 6, 2024
Spring Boot and JOOQ - Getting started
This article will show how to use jOOQ in your spring boot projects. Why do we need jOOQ? There is a lot of pain using JPA and Hibernate. That is why we have something jOOQ. First, we need to create a database schema. In this article, we will develop a simple CRUD (create, read, update, and delete) application to manage goods. The first step is to design our database. The application will contain only one table — goods. The table looks like below.
January 3, 2024
JUnit 5 - How to write more test with less code
Introduction In this article, I will show and explain how you can write more tests with relatively small changes in your code. Recently, one of my colleagues wrote a massive test with repetitive code. The difference between test cases was only data that was submitted to the service. I will use JUnit 5 in this article, but feel free to check the library docs you use for writing tests.
December 31, 2023
Spring Cloud Functions, Kafka - How to interact asynchronous
Introduction This article will show how to use the Spring Cloud Functions projects. The Spring Cloud Functions is the best approach to implementing a straightforward business logic. Nowadays, the usage of message brokers such as Kafka has increased. I will implement a simple system in this article, as shown below. Diagram of developing system Implementation I will start with a simple example of a cloud function, which is the same as a rest endpoint in the classical spring boot web application. You can create a project from your favorite IDE or from Spring Initliazr.
December 24, 2023