Posts

Implementing Filters in Spring Web and Spring WebFlux

Image
Introduction Team is proactively working on spring boot 3.x upgrade and java 17. this post guide you how to migrate those Filters in both Spring Web and Spring WebFlux. Filters are a fundamental aspect of web development, allowing developers to intercept and manipulate incoming requests and outgoing responses. In Spring applications, filters can be implemented to perform tasks such as logging, authentication, authorization, and request/response modification. This guide will demonstrate how to   ...

A Comprehensive Guide to Context Path Configuration in Spring Web and Spring WebFlux

Image
Introduction Team is working on spring boot version upgrade to 3.x and java to java 17. We noticed a few changes required for Context Path. The context path plays a crucial role in web applications, serving as the prefix to all URLs within the application. Configuring the context path correctly is essential, especially in scenarios where multiple applications are deployed on the same server. In this guide, we'll explore how to configure the context path in both Spring Web and Spring WebFlux app   ...

A Comprehensive Guide to Using H2 In-Memory Database in Unit Tests

Image
Introduction Unit testing is an integral part of software development, ensuring that individual components of an application function as expected in isolation. When testing components that interact with databases, using an in-memory database is a common approach to achieve fast and reliable tests. In this guide, we'll explore how to use the H2 in-memory database in your unit tests with Spring Boot. Step 1: Add H2 Dependency First, ensure that you have the H2 database dependency added to your   ...

why @WithMockUser still got 401 unauthorized

Image
@AutoConfigureMockMvc for none reactive spring application, the Servlet API and Servlet containers, spring-boot-starter-web, please use MockMvc. import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) @AutoConfigureMockMvc @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class IntegrationTestsBase { @Autowired protected MockMvc mockMvc; ... mockMvc.perform(   ...

Leveraging Mock Server in Spring Boot Integration Tests

Image
Introduction: Integration testing is crucial for ensuring the robustness and reliability of Spring Boot applications. However, testing against real external services can introduce complexity and dependencies, leading to slower and less predictable tests. In this tutorial, we'll explore how to use a Mock Server in Spring Boot integration tests to simulate external dependencies, enabling faster and more deterministic testing. What is a Mock Server? A Mock Server is a tool that allows developers t   ...