Spring
Let's Optimize the Annotation @SpringBootTest (feat. @DataJpaTest, @WebMvcTest)
When I first joined the company, I was concerned about the lengthy testing times. (about 28 minutes) Interestingly, my colleagues were not bothered by it since this was the usual time consumption, but having come from a previous company where it took only 2-3 minutes, enduring such extended times was very difficult 🤣 At that time, we were not using tools like Testcontainers to launch containers and all tests were based on Mockito unit testing, so I couldn’t understand why the tests took so long.
January 20, 2025
Applying Redis Cache in Spring Boot
A while ago, I conducted API load testing using a tool called Locust. I want to share my experience of implementing Redis Cache to resolve response delays for a particular API that occurred at that time. What is Cache? Cache refers to a memory area where data or values are pre-copied so they can be accessed quickly. RDBs are stored on disk, so they are incomparable in speed to Redis, which is simply stored in memory.
January 19, 2025
Testing QueryDSL with Testcontainers in Spring
When using QueryDSL in real-world projects, there can be times when it’s hard to determine if the query is functioning correctly. In such cases, you can use Testcontainers to bring up a database in a container environment identical to the real one, execute the query, and compare the results to conduct tests. Why Test QueryDSL? In fact, executing queries by accessing a database is possible not only with QueryDSL but also with a variety of ORM frameworks such as JPA and MyBatis.
August 19, 2024
Exploring the Differences Between Spring @Configuration and @Component Annotations
In Spring, there are mainly two ways to register dependencies (also known as Bean classes). These are the @Configuration and @Component, which will be discussed below. A Bean refers to an object managed by the Spring IoC Container, as explained in a previous post. @Configuration and @Component are methods for registering these Beans. Let’s explore the differences between them. Using @Component @Component is one method to register a Bean in the Spring IoC Container.
July 9, 2024
Logging Trace ID and Span ID in Spring Using Micrometer
When logging for debugging purposes, especially in distributed systems, it can be challenging to trace the flow of a transaction through logging. In production environments, various parameters of a normal request or return information may be logged across different stages for debugging. A characteristic of such logs is that when multiple requests come in simultaneously, the logs may get intermingled, making it difficult to discern which log belongs to which request.
June 24, 2024
Output Pattern and JSON Logs Using Logback in Spring Boot
When operating an API server, it is common to leave logs for operational reasons or debugging. Traditionally, in Spring, while there is a format for leaving logs, they are often left in Raw Text form, which I think is better for visibility than leaving them in JSON form. However, the story is different when searching and filtering logs. In platforms like AWS CloudWatch where logs can be searched, logging in Raw Text format makes it difficult to filter which function emitted which data.
June 17, 2024
(JAVA) Mocking Static Methods in Spring Services
Spring generally follows a Layered Architecture, with services primarily handling business logic. Often, static methods are used, but in the case of regular components, dynamic runtime binding facilitates replacing the object implementing the interface with a mock object during testing. For static methods, binding occurs at compile time, making them challenging to mock. So, what can be done? 1. Wrapper Class Traditionally, you can componentize static methods.
June 15, 2024
(JAVA) Mocking Methods Within the Same Service in Spring
In general, Spring follows a Layered Architecture, and services primarily handle business logic. As the code within a service increases, similar code tends to accumulate. In such cases, some separate out the common logic into additional layers, but often it is processed by declaring common methods within the service. For example, consider the following: @Service public class SomeService { public void methodA() { // do something } public void methodB() { methodA(); // do something } public void methodC() { methodA(); // do something } } In the code above, methodA is a method commonly used in both methodB and methodC.
May 30, 2024
Let's Learn About Dependency Injection (DI)
In this post, we will discuss Dependency Injection (DI), which is one of the important concepts of the Spring Framework. DI is a crucial concept in Spring, and it frequently appears in job interviews, so it is essential to know. First, let’s understand what dependency is. Dependency When object A depends on object B, it is closely related to the concept of composition. Let’s take a look at the code.
February 24, 2022
Let's Learn About Spring Beans
Today I considered explaining Spring MVC, but before doing so, I thought it might be helpful to introduce some basic knowledge about Spring that one should know to understand MVC. Spring Bean? A Spring Bean refers to an object that is managed by the Spring Container. But isn’t that a bit strange? An object managed by Spring? Could it be an object defined within Spring’s library?
February 24, 2022
Let's Learn About the Autowired Annotation
Last time, we learned about Spring’s DI, didn’t we? Go to “Dependency Injection” Post Today, we are going to explore the @Autowired annotation, which is closely related to DI. First of all, whether it is a method or an annotation, the name carries a very important meaning. Autowired? What does it feel like? Doesn’t it feel like “automatically connected”? Let’s take a look even if we’re not sure what it is.
February 24, 2022