Skip to main content

Posts

Integrating Azure AD with React.js Using @azure/msal-browser 2.15.0 and @azure/msal-react 1.0.1

In this blog post, we will explore how to integrate Azure AD with a React.js application using the @azure/msal-browser and @azure/msal-react libraries. Prerequisites Node.js and npm installed on your machine React.js project set up ( create-react-app or similar) Azure AD tenant and registered application Step 1: Install Dependencies Start by navigating to your React.js project directory and install the required dependencies: $ npm install @azure/msal-browser@2.15.0 @azure/msal-react@1.0.1 Step 2: Configure Azure AD Next, you need to configure your Azure AD tenant and registered application. Follow these steps: Sign in to the Azure portal and navigate to the Azure Active Directory section. Under the "App registrations" tab, select your registered application or create a new one. Make note of the "Application (client) ID" as you'll need it later. Under the "Authentication" section

Handling Exceptions and Returning User-Friendly Messages in Spring Boot

In a Spring Boot application, it's crucial to handle exceptions gracefully and provide user-friendly error messages when something goes wrong. One way to achieve this is by using a controller advice, which allows you to intercept and handle exceptions globally for all controllers. In this blog post, we'll explore how to write a controller advice in Spring Boot that catches all exceptions and returns user-friendly messages. Setting up the Controller Advice First, let's create a new class annotated with @ControllerAdvice and implement the ResponseEntityExceptionHandler class. This class will handle exceptions globally for all controllers in our Spring Boot application. import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.servlet.mvc.method.annotation.ResponseE

The Power of CI/CD for Spring Boot Projects: Streamlining Development and Ensuring Quality

Introduction Welcome to my blog post about CI/CD for Spring Boot projects. In this article, we'll explore the importance of Continuous Integration and Continuous Deployment in the context of Spring Boot applications. We'll discuss how CI/CD can streamline your development workflow, improve code quality, and help you deliver high-quality applications more efficiently. What is CI/CD? CI/CD stands for Continuous Integration and Continuous Deployment (or Continuous Delivery). It is a set of practices and processes that enable developers to build, test, and deploy code changes more frequently and reliably. CI focuses on integrating code changes from multiple developers into a shared repository, while CD focuses on automating the release and deployment of the integrated code. In traditional software development approaches, developers would work on separate branches for an extended period, leading t

Choosing the Best Templating Engine for Your Java Project: FreeMarker, Thymeleaf, or Velocity?

Comparing FreeMarker, Thymeleaf, and Velocity Introduction to Templating Engines Templating engines are powerful tools that allow developers to separate the presentation logic from the business logic in web applications. They provide a way to define dynamic templates that can be rendered with data to produce HTML output. Framework Language Popularity Features FreeMarker Java Popular Robust, flexible, and widely used in Java projects. Thymeleaf Java Very popular Seamless integration with Spring, excellent support for HTML5, and natural templates. Velocity Java Less popular Lightweight, simple, and easy to learn. Code Examples FreeMarker Table Example: <table> <tr> <th>Name</th> <th>Age</th>

A Deep Dive into JPA Fetch Types: Exploring the Default Loading Strategy

When working with Java Persistence API (JPA), it's essential to understand the different fetch types for entity associations. In JPA, you can define the fetch type for relationships between entities, which determines how related entities are loaded from the database. In JPA, the default fetch types for different mappings are as follows: One-to-One Relationship For a one-to-one relationship, the default fetch type is FetchType.EAGER . This means that the associated entity will be loaded from the database eagerly, along with the main entity. @Entity public class Author { // ... @OneToOne(fetch = FetchType.EAGER) private Address address; // ... } @Entity public class Address { // ... } One-to-Many Relationship For a one-to-many relationship, the default fetch type is FetchType.LAZY . This means that the associated entities will not be loaded from the database until explicit

Configuring Multiple Profiles in a Single YAML File for Spring Boot Application

Spring Boot provides a convenient way to configure application properties using YAML files. In a typical scenario, you might have different configurations for different environments such as development, testing, and production. Instead of maintaining multiple YAML files for each profile, you can configure multiple profiles within a single YAML file. This approach simplifies the configuration management process. Let's see how to achieve this. Step 1: Create a YAML Configuration File First, create a YAML file (e.g., application.yml ) in your Spring Boot project's resource directory. This file will contain the configuration properties for all the profiles you want to define. spring: profiles: active: dev logging: level: root: INFO com.example: DEBUG # Configuration for the 'dev' profile --- spring: profiles: dev database: url: jdbc:mysql://localhost:3306/devdb username: devuser password: devpassword # Co

Mastering Property Override: spring.datasource.url in Spring Boot Explained

When working with a Spring Boot application, you might need to override the spring.datasource.url property in the application.properties file to connect to a different database. Ways to Override the Property There are several ways to override the spring.datasource.url property: Using Command Line Arguments: You can pass the property value as a command line argument when running the application. For example: java -jar my-application.jar --spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase Using System Environment Variables: Set the property value as an environment variable. For example, in a Unix-based system: export SPRING_DATASOURCE_URL=jdbc:mysql://localhost:3306/mydatabase Using an External Configuration File: You can provide an external properties file containing the override value. For example, create a file named application.yaml with the following content: spring: datasource: url: jdbc:mysql://local

Undeploying Processes in Spring Boot Camunda: A Step-by-Step Guide

In this blog post, we will discuss how to undeploy all processes when starting up a Spring Boot Camunda application. We will utilize the following code snippet: @PostConstruct public void undeployAll() { RepositoryService repositoryService = processEngine.getRepositoryService(); List<Deployment> deployments = repositoryService.createDeploymentQuery().list(); for (Deployment deployment : deployments) { repositoryService.deleteDeployment(deployment.getId(), true); } } Introduction When working with a Spring Boot Camunda application, there might be instances where you need to undeploy all existing processes during application startup. This could be necessary when you want to ensure a clean slate or update the deployed processes. In this blog post, we will explore a simple approach to achieve this using the provided code snippet. Step-by-Step Guide Step 1: Include Camunda Dependencies Make sure your Spring Boot project includes the necessar

Creating an App-like Experience: Exploring PWA in React Create App

In this blog post, we will learn how to configure a Progressive Web App (PWA) in Create React App and display the install icon on the Chrome browser. Step 1: Setting up a Create React App project First, make sure you have create-react-app installed globally. If not, install it by running the following command: npx create-react-app my-pwa Step 2: Configuring the manifest file Navigate to your project directory and open the public/manifest.json file. Modify the file with the following content: { "name": "My PWA", "short_name": "My PWA", "start_url": ".", "display": "standalone", "theme_color": "#000000", "background_color": "#ffffff", "icons": [ { "src": "path/to/icon.png", "sizes": "192x192", "type": "image/png" } ] } Step 3:

Easy SSL Certificate Generation for Local Testing: A Complete Guide with mkcert

In this tutorial, we'll learn how to create an SSL certificate using mkcert , a simple tool developed by Filippo Valsorda. Mkcert allows us to quickly generate trusted development certificates for local testing purposes. Prerequisites Go to the mkcert repository on GitHub and follow the installation instructions for your operating system. Make sure you have Go installed on your machine. Step 1: Install mkcert To install mkcert, follow the instructions provided in the repository's README . Once installed, you should have the mkcert command available in your terminal. Next, run the following command to install the root CA (Certificate Authority) certificate into the system's trust store: mkcert -install This step is required to ensure that the certificates generated by mkcert are recognized as trusted by your operating system and web browsers. Step 2: Generate a Local SSL Certificate O